1. Window Appears Briefly Then Disappears

Hello all,

I am currently wrapping the RayLib, https://www.raylib.com/index.html, while I don't have all of it wrapped yet, I decided to make a small test program to see if it is working. Right now, the window appears, but goes away quickly. Here is the code

--Wrapper Code 
public constant xInitWindow = define_c_proc(ray,"InitWindow",{C_INT,C_INT,C_POINTER}), 
				xWindowShouldClose = define_c_func(ray,"WindowShouldClose",{},C_BOOL), 
				xCloseWindow = define_c_proc(ray,"CloseWindow",{}) 
 
public procedure InitWindow(atom w,atom h,sequence title) 
 
 atom str = allocate_string(title,1) 
 c_proc(xInitWindow,{w,h,str}) 
	 
end procedure 
 
public function WindowShouldClose() 
 
 return c_func(xWindowShouldClose,{}) 
	 
end function 
 
public procedure CloseWindow() 
 
 c_proc(xCloseWindow,{}) 
	 
end procedure 
--Example Program 
include std/machine.e 
include Euraylib.ew 
 
atom width = 800, height = 600 
 
InitWindow(width,height,"Basic Win") 
 
	SetTargetFPS(30) 
 
while not WindowShouldClose()  do 
	 
	BeginDrawing() 
	 
	ClearBackground(0) 
	 
	EndDrawing() 
 
end while 
 
CloseWindow() 

I know it might be possible, I need to wrap more of the library. The C code below is the example, I am trying to re-create in Euphoria code. Not sure, but this might help with documentation https://www.raylib.com/cheatsheet/cheatsheet.html

 
#include "raylib.h" 
 
int main(void) 
{ 
    // Initialization 
    //-------------------------------------------------------------------------------------- 
    const int screenWidth = 800; 
    const int screenHeight = 450; 
 
    InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); 
 
    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second 
    //-------------------------------------------------------------------------------------- 
 
    // Main game loop 
    while (!WindowShouldClose())    // Detect window close button or ESC key 
    { 
        // Update 
        //---------------------------------------------------------------------------------- 
        // TODO: Update your variables here 
        //---------------------------------------------------------------------------------- 
 
        // Draw 
        //---------------------------------------------------------------------------------- 
        BeginDrawing(); 
 
            ClearBackground(RAYWHITE); 
 
            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); 
 
        EndDrawing(); 
        //---------------------------------------------------------------------------------- 
    } 
 
    // De-Initialization 
    //-------------------------------------------------------------------------------------- 
    CloseWindow();        // Close window and OpenGL context 
    //-------------------------------------------------------------------------------------- 
 
    return 0; 
} 
 

new topic     » topic index » view message » categorize

2. Re: Window Appears Briefly Then Disappears

Hi

A useful debug tool is the console. You want to find where the program gets to before crunching out.

Put a
puts(1, "Got here\n")
at various points in the program, and it will print it to the console when it gets there. Obviously if it doen't get there, you won't see it.

You can also use
? asequence

or
printf(1, "%s, %d\n", {astring, anumber} )
to print out some values

These will appear in a console window (possibly behind your main window - check the taskbar)

When an Eu progrom crashes in the middle of a dll call, you won't get an error message, and sometimes it's useful to find which call is causing the issue.

also have you tried replacing
whiel not wndowshouldclose() do with while 1 do ?

Cheers

Chris

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

3. Re: Window Appears Briefly Then Disappears

--without warning 
 
include std/machine.e 
include Euraylib.ew 
 
--atom width = 800, height = 600 
 
puts(1,"Got here\n") 
InitWindow(800,600,"Basic Win") 
 
puts(1,"Got here\n") 
 
	SetTargetFPS(30) 
 
while not WindowShouldClose()  do 
	 
	BeginDrawing() 
	 
	puts(1,"Got here\n") 
	 
	ClearBackground(0) 
	 
	EndDrawing() 
 
end while 
 
CloseWindow() 

From the command prompt 
Got here 
INFO: Initializing raylib 2.5 
INFO: Display device initialized successfully 
INFO: Display size: 1680 x 1050 
INFO: Render size: 800 x 600 
INFO: Screen size: 800 x 600 
INFO: Viewport offsets: 0, 0 
INFO: GLAD: OpenGL extensions loaded successfully 
INFO: OpenGL 3.3 Core profile supported 
INFO: GPU: Vendor:   NVIDIA Corporation 
INFO: GPU: Renderer: GeForce GTX 970/PCIe/SSE2 
INFO: GPU: Version:  3.3.0 NVIDIA 430.86 
INFO: GPU: GLSL:     3.30 NVIDIA via Cg compiler 
INFO: Number of supported extensions: 374 
INFO: [EXTENSION] DXT compressed textures supported 
INFO: [EXTENSION] ETC2/EAC compressed textures supported 
INFO: [EXTENSION] Anisotropic textures filtering supported (max: 16 
INFO: [EXTENSION] Mirror clamp wrap texture mode supported 
INFO: [TEX ID 1] Texture created successfully (1x1 - 1 mipmaps) 
INFO: [TEX ID 1] Base white texture loaded successfully 
INFO: [SHDR ID 1] Shader compiled successfully 
INFO: [SHDR ID 2] Shader compiled successfully 
INFO: [SHDR ID 3] Shader program loaded successfully 
INFO: [SHDR ID 3] Default shader loaded successfully 
INFO: Internal buffers initialized successfully (CPU) 
INFO: Internal buffers uploaded successfully (GPU) 
INFO: OpenGL default states initialized successfully 
INFO: [TEX ID 2] Texture created successfully (128x128 - 1 mipmaps) 
INFO: [TEX ID 2] Default font loaded successfully 

I tried adding in the puts(1,"Got here\n") and it appears InitWindow is where the problem. However in the command prompt, it says everything initialized successfully. Again, I haven't finished wrapping the library, but I thought a small program would be fine just to make sure it works. I also tried the While1 do, and it still appeared briefly, then closed.

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

4. Re: Window Appears Briefly Then Disappears

Icy_Viking said...
--Wrapper Code 
public constant xInitWindow = define_c_proc(ray,"InitWindow",{C_INT,C_INT,C_POINTER}), 

Looks like raylib is using CDECL calling convention. You need to prefix function names with a "+" to override the default STDCALL calling convention on Windows.

https://github.com/raysan5/raylib/blob/master/src/raylib.h#L79

-Greg

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

5. Re: Window Appears Briefly Then Disappears

ghaberek said...
Icy_Viking said...
--Wrapper Code 
public constant xInitWindow = define_c_proc(ray,"InitWindow",{C_INT,C_INT,C_POINTER}), 

Looks like raylib is using CDECL calling convention. You need to prefix function names with a "+" to override the default STDCALL calling convention on Windows.

https://github.com/raysan5/raylib/blob/master/src/raylib.h#L79

-Greg

Thanks Greg, I knew the issue might be simple and it was. That fixed it!

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

Search



Quick Links

User menu

Not signed in.

Misc Menu