1. raylibshim - A shim library for Euphoria and Raylib

Forked from Re: Texture Not Showing

Here's the start of a raylib shim library: https://github.com/ghaberek/raylibshim

The C code should be complete, but there's a lot of work to do on the Euphoria side to get it to set up the structres and pull out the values.

As it's written, it still takes structures-by-value as parameters to the C functions.

We could take this a step further and accept pointers to these structures, then pass the dereferenced value to the C function instead. (If that makes sense.)

-Greg

new topic     » topic index » view message » categorize

2. Re: raylibshim - A shim library for Euphoria and Raylib

Here's something I did to make passing structures-by-value a bit easier.

First, create a sequence containing the required types:

constant C_STRING = C_POINTER 
 
constant C_IMAGE = { 
    C_POINTER, -- void* data 
    C_INT,     -- int width 
    C_INT,     -- int height 
    C_INT,     -- int mipmaps 
    C_INT      -- int format 
} 

Then, instead of passing the types as {C_TYPE,C_TYPE,...} append them together, like this:

constant 
    shimLoadTexture             = define_c_proc( raylibshim, "+shimLoadTexture", C_STRING & C_POINTER ), 
    shimLoadTextureFromImage    = define_c_proc( raylibshim, "+shimLoadTextureFromImage", C_IMAGE & C_POINTER ), 
$ 

This makes it a lot easier to read and manage.

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: raylibshim - A shim library for Euphoria and Raylib

Thanks Greg, this will come in handy. I know some C and C++ programming. So it shouldn't be too hard to deal with.

EDIT: OK, I was able to incorpate rayshimlib.c into the raylib visual studio project file and build it from there. After checking the raylib.DLL, I noticed that the shim functions are inside of the DLL, so they can be loaded. I had to do a little reworking with the Euraylib.ew file, but I got it to work!

--Had to change a couple function names, but it works. I'll add the rest of the functions soon.  
 
--Maybe I have to rework this a little?  
public constant xDrawTexture = define_c_proc(ray,"+DrawTexture",{C_POINTER,C_INT,C_INT,C_UINT,C_UINT,C_UINT,C_UINT}) 
 
public procedure DrawTexture(atom tex,atom x,atom y,atom r,atom g,atom b,atom a) 
 
 c_proc(xDrawTexture,{tex,x,y,r,g,b,a}) 
	 
end procedure 
 
--shim functions 
constant 
	shimLoadTexture             = define_c_proc( ray, "+shimLoadTexture", C_STRING & C_POINTER ), 
	shimLoadTextureFromImage    = define_c_proc( ray, "+shimLoadTextureFromImage", C_IMAGE & C_POINTER ), 
$ 
 
public function gLoadTexture( sequence filename ) 
	 
	atom texture = allocate_data( SIZEOF_TEXTURE2D, TRUE ) 
	mem_set( texture, NULL, SIZEOF_TEXTURE2D ) 
	 
	c_proc( shimLoadTexture, {allocate_string(filename,TRUE),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 
 
public function gLoadTextureFromImage( sequence image ) 
	 
	atom data    = image[IMAGE_DATA] 
	atom width   = image[IMAGE_WIDTH] 
	atom height  = image[IMAGE_HEIGHT] 
	atom mipmaps = image[IMAGE_MIPMAPS] 
	atom format  = image[IMAGE_FORMAT] 
	 
	atom texture = allocate_data( SIZEOF_TEXTURE2D, TRUE ) 
	mem_set( texture, NULL, SIZEOF_TEXTURE2D ) 
	 
	c_proc( shimLoadTextureFromImage, {data,width,height,mipmaps,format,texture} ) 
	 
	atom id = peek4u( texture + Texture2D_id ) 
	width   = peek4s( texture + Texture2D_width ) 
	height  = peek4s( texture + Texture2D_height ) 
	mipmaps = peek4s( texture + Texture2D_mipmaps ) 
	format  = peek4s( texture + Texture2D_format ) 
	 
	return {id,width,height,mipmaps,format} 
end function 

Now the problem is, I don't know how to display the image using DrawTexture?

without warning 
 
include std/machine.e 
include std/convert.e 
 
include Euraylib.ew 
--include raylibshim.e 
 
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") 
 
gLoadTextureFromImage("raylib_logo.png") --this works fine. 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
 
	ClearBackground(black) 
	 
	DrawText("This is Texture",1,1,20,yello) 
	 
    DrawTexture(1,50,50,0,0,0,0) --not sure how to load display the texture 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 
 
new topic     » goto parent     » topic index » view message » categorize

4. Re: raylibshim - A shim library for Euphoria and Raylib

Hi, You are passing wrong arguments to DrawTexture function.

C DrawTexture function definition

RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); 

Example

 
include flags.e 
include std/convert.e 
include Euraylib.ew  
  
constant width = 800  
constant height = 450  
  
atom black = bytes_to_int({0, 0, 0, 0})  
atom yello = bytes_to_int({255, 255, 0, 255})  
atom white = bytes_to_int({255, 255, 255, 255})  
  
InitWindow(width,height,"Simple Texture")  
 
while not WindowShouldClose() do  
  
	BeginDrawing()  
  
	ClearBackground(black)  
	  
	-- 1 placeholder 
	-- 2 defalut font 
	-- 3 gLoadTextureFromImage("raylib_logo.png") 
	 
	-- we are passing font texture loaded by defalut (Index 2) 
	sequence texutre_info = {2, 150, 150, 1, 0} 
	DrawTexture(texutre_info, width / 2, height / 2, white)  
	 
	DrawText("This is Texture",1,1,20,yello)  
	  
	EndDrawing()  
	  
end while  
  
--UnloadTexture(tex)  
 

Euraylib.ew

public constant xDrawTexture = define_c_proc(ray,"+DrawTexture",{C_UINT,C_INT,C_INT,C_INT,C_INT,C_INT,C_INT,C_UINT}), 
				xDrawTextureV = define_c_proc(ray,"+DrawTextureV",{C_POINTER,C_FLOAT,C_FLOAT,C_UINT}), 
				xDrawTextureEx = define_c_proc(ray,"+DrawTextureEx",{C_POINTER,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_UINT}), 
				xDrawTextureRec = define_c_proc(ray,"+DrawTextureRec",{C_POINTER,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_UINT}), 
				xDrawTextureQuad = define_c_proc(ray,"+DrawTextureQuad",{C_POINTER,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_UINT}), 
				xDrawTexturePro = define_c_proc(ray,"+DrawTexturePro",{C_POINTER,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_UINT}), 
				xDrawTextureNPatch = define_c_proc(ray,"+DrawTextureNPatch",{C_POINTER,C_UINT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_FLOAT,C_UINT}) 
			 
 
				 
public procedure DrawTexture(sequence seq, atom x,atom y,atom tint)  
 
 c_proc(xDrawTexture,{seq[1],seq[2],seq[3],seq[4],seq[5],x,y,tint})  
	 
end procedure 
new topic     » goto parent     » topic index » view message » categorize

5. Re: raylibshim - A shim library for Euphoria and Raylib

Well, I got it to work, somewhat. It doesen't show the image, but it does show a bunch of garbled random characters.

public 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(sequence seg,atom x,atom y,atom tint) 
 
 c_proc(xDrawTexture,{seg[1],seg[2],seg[3],seg[4],seg[5],x,y,tint}) 
	 
end procedure 
without warning 
 
include std/machine.e 
include std/convert.e 
 
include Euraylib.ew 
--include raylibshim.e 
 
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") 
 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
 
	ClearBackground(black) 
	 
	DrawText("This is Texture",1,1,20,yello) 
	 
	 
    gLoadTextureFromImage("raylib_logo.png")  
	 
    sequence texture_info = {2,150,150,1,0} 
     
	DrawTexture(texture_info,width / 2, height / 2,white) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 
new topic     » goto parent     » topic index » view message » categorize

6. Re: raylibshim - A shim library for Euphoria and Raylib

gLoadTextureFromImage("raylib_logo.png")   
sequence texture_info = {3,150,150,1,0} -- Have you tried to change the first element of the sequence to 3?? 

{x,150,150,1,0} where x:

1 = placeholder

2 = defalut font texture

3 = your texture 1 ("raylib_logo.png")

4 = your texture n

new topic     » goto parent     » topic index » view message » categorize

7. Re: raylibshim - A shim library for Euphoria and Raylib

Maccuq said...
gLoadTextureFromImage("raylib_logo.png")   
sequence texture_info = {3,150,150,1,0} -- Have you tried to change the first element of the sequence to 3?? 

{x,150,150,1,0} where x:

1 = placeholder

2 = defalut font texture

3 = your texture 1 ("raylib_logo.png")

5 = your texture n

Thanks for the tips. After playing around, I got it!

without warning 
 
include std/machine.e 
include std/convert.e 
 
include Euraylib.ew 
--include raylibshim.e 
 
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 yellow = bytes_to_int({255,255,0,255}) 
atom blue = bytes_to_int({0,0,255,255}) 
 
InitWindow(width,height,"Simple Texture") 
 
 
while not WindowShouldClose() do 
 
	BeginDrawing() 
 
	ClearBackground(blue) --changed background to blue 
	 
	DrawText("This is Texture",1,1,20,yellow) 
	 
	 
    gLoadTexture("raylib_logo.png")  --changed to gLoadTexture from gLoadTextureFromImage 
	 
    sequence texture_info = {3,256,256,0,0} --3 made the image appear 
     
	DrawTexture(texture_info,10, 50,white) --changed location of where image appears ons creen (the image is 256 x 256 in width & height) 
	 
	EndDrawing() 
	 
end while 
 
CloseWindow() 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu