1. Texture Not Showing
- Posted by Icy_Viking Jul 18, 2019
- 1545 views
Hello,
Working on my Raylib wrapper and I cannot get a texture to show.
C code
typedef struct Texture2D { unsigned int id; // OpenGL texture id int width; // Texture base width int height; // Texture base height int mipmaps; // Mipmap levels, 1 by default int format; // Data format (PixelFormat type) } Texture2D; void DrawTexture(Texture2D texture, int posX, int posY, Color tint)
Eu Wrapper code
--I have changed the wrapper function to accept the struct as individual variables. ublic constant xDrawTexture = define_c_proc(ray,"+DrawTexture",{C_UINT,C_INT,C_INT,C_INT,C_INT,C_INT,C_INT,C_UINT}) public procedure DrawTexture(atom id,atom w,atom h,atom mip,atom mat, atom x,atom y,atom tint) c_proc(xDrawTexture,{id,w,h,mip,mat,x,y,tint}) end proce
Eu Code (Load Texture Program)
without warning include std/machine.e include std/convert.e include Euraylib.ew constant width = 800 constant height = 450 atom black = bytes_to_int({0,0,0,0}) atom white = bytes_to_int({255,255,255,255}) atom yello = bytes_to_int({255,255,0,255}) InitWindow(width,height,"Simple Texture") atom tex = LoadTexture("raylib_logo.png") while not WindowShouldClose() do BeginDrawing() ClearBackground(black) --Texture does not show DrawTexture(tex,256,256,1,1,width,height,yello) --Text does show DrawText("This is Texture",1,1,20,yello) EndDrawing() end while UnloadTexture(tex) CloseWindow()
2. Re: Texture Not Showing
- Posted by Maccuq Jul 19, 2019
- 1502 views
Hi, texture is not showing, because it is not loading. C function 'LoadTexture' is returning struct, not a pointer to a struct.
https://openeuphoria.org/forum/122140.wc#122140
Euraylib.ew
public constant xLoadImage = define_c_func(ray,"+LoadImage",{C_POINTER},C_POINTER),
Raylib.h
RLAPI Texture2D LoadTexture(const char *fileName); RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animsCount);
Euphoria output
WARNING: [c_proc/c_func] Image fileformat not supported WARNING: [c_proc/c_func] Image could not be loaded WARNING: Texture could not be created
3. Re: Texture Not Showing
- Posted by Icy_Viking Jul 19, 2019
- 1431 views
Hi, texture is not showing, because it is not loading. C function 'LoadTexture' is returning struct, not a pointer to a struct.
https://openeuphoria.org/forum/122140.wc#122140
Euraylib.ew
public constant xLoadImage = define_c_func(ray,"+LoadImage",{C_POINTER},C_POINTER),
Raylib.h
RLAPI Texture2D LoadTexture(const char *fileName); RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animsCount);
Euphoria output
WARNING: [c_proc/c_func] Image fileformat not supported WARNING: [c_proc/c_func] Image could not be loaded WARNING: Texture could not be created
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.
4. Re: Texture Not Showing
- Posted by ghaberek (admin) Jul 19, 2019
- 1425 views
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 ); }
constant Texture2D__id = 0, -- unsigned int Texture2D__width = 4, -- int Texture2D__height = 8, -- int Texture2D__mipmaps = 12, -- int Texture2D__format = 16, -- int SIZEOF_TEXTURE2D = 20 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.
-Greg
5. Re: Texture Not Showing
- Posted by Icy_Viking Jul 19, 2019
- 1410 views
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 ); }
constant Texture2D__id = 0, -- unsigned int Texture2D__width = 4, -- int Texture2D__height = 8, -- int Texture2D__mipmaps = 12, -- int Texture2D__format = 16, -- int SIZEOF_TEXTURE2D = 20 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.
-Greg
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.
6. Re: Texture Not Showing
- Posted by ghaberek (admin) Jul 19, 2019
- 1400 views
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.
Right, which is why I said:
I'd like to implement this functionality in the future, but for now it simply doesn't exist.
If you need some help setting up a shim library, let me know. I'd be happy to help.
-Greg
7. Re: Texture Not Showing
- Posted by Icy_Viking Jul 20, 2019
- 1378 views
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.
Right, which is why I said:
I'd like to implement this functionality in the future, but for now it simply doesn't exist.
If you need some help setting up a shim library, let me know. I'd be happy to help.
-Greg
Sure I'd like to know how to setup a shim library.
Forked into: raylibshim - A shim library for Euphoria and Raylib
8. Re: Texture Not Showing
- Posted by ghaberek (admin) Jul 20, 2019
- 1380 views
Sure I'd like to know how to setup a shim library.
If you're not yet comfortable with C programming, I suggest the following documents:
- 101 Essential C (45 pages)
- 102 Pointers and Memory (31 pages)
- 107 Unix Programming Tools (16 pages)
-Greg