Re: Texture Not Showing

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...
Icy_Viking said...

Thanks that put it in the right direction. I changed it to the C_UINT from a C_POINTER, but still not showing. I also tried LoadImageRaw function and still nothing. Probably going to have to use poke and peek commands I assume in order to get it working.

The problem is Euphoria doesn't have a concept of returning anything more than a single value from a C function call.

The Texture2D structure is as follows:

typedef struct Texture2D { 
    unsigned int id; 
    int width; 
    int height; 
    int mipmaps; 
    int format; 
} Texture2D; 

In order for Euphoria to support this, you'd have to define the C function as follows:

constant C_TEXTURE2D = { 
  C_UINT, -- unsigned int id 
  C_INT,  -- int width 
  C_INT,  -- int height 
  C_INT,  -- int mipmaps 
  C_INT   -- int format 
constant xLoadTexture = define_c_func( raylib, "+LoadTexture", {C_POINTER}, C_TEXTURE2D ) -- note: C_TEXTURE2D is a sequence! 

I'd like to implement this functionality in the future, but for now it simply doesn't exist.

In order to get around this in the past, I've written "shim" libraries in C return the data via a pointer in memory.

void LoadTextureEx( const char* filename, Texture2D* texture ) 
    *texture = LoadTexture( filename ); 

  Texture2D__id      =  0, -- unsigned int 
  Texture2D__width   =  4, -- int 
  Texture2D__height  =  8, -- int 
  Texture2D__mipmaps = 12, -- int 
  Texture2D__format  = 16, -- int 
constant xLoadTextureEx = define_c_proc( shimlib, "+LoadTextureEx", {C_POINTER,C_POINTER} ) 
public function LoadTexture( sequence filename ) 
    atom texture = allocate_data( SIZEOF_TEXTURE2D ) 
    mem_set( texture, NULL, SIZEOF_TEXTURE2D ) 
    c_proc( xLoadTextureEx, {allocate_string(filename),texture} ) 
    atom id      = peek4u( texture + Texture2D__id ) 
    atom width   = peek4s( texture + Texture2D__width ) 
    atom height  = peek4s( texture + Texture2D__height ) 
    atom mipmaps = peek4s( texture + Texture2D__mipmaps ) 
    atom format  = peek4s( texture + Texture2D__format ) 
    return {id,width,height,mipmaps,format} 
end function 

You'd have to do this for every function that returns a structure.


I tried the C_TEXTURE2D = {C_UINT,C_INT...} and that didn't work. It came back with an error type_check failure. So I'm assuming the "shim" option is probably the way to go.

new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu