Simple OpenGL Clear color test doesn't work

802 views
Skip to first unread message

Michael IV

unread,
Mar 8, 2014, 11:59:50 AM3/8/14
to emscripte...@googlegroups.com
I wrote a test which just clears framebuffer color:



#include <stdio.h>
#include <stdlib.h>


#include <GL/glfw.h>
#include <emscripten/emscripten.h>

int main( void )
{
int     width, height, running, x;
double  t;

// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
exit( EXIT_FAILURE );
}

// Open OpenGL window
if( !glfwOpenWindow( 640, 480, 8,8,8,8, 16,0, GLFW_WINDOW ) )
{
fprintf( stderr, "Failed to open GLFW window\n" );

glfwTerminate();
exit( EXIT_FAILURE );
}

glfwSetWindowTitle( "Spinning Triangle" );



// Enable sticky keys
// glfwEnable( GLFW_STICKY_KEYS );

// Enable vertical sync (on cards that support it)
//glfwSwapInterval( 1 );

// Main loop
running = GL_TRUE;
int i = 0;
while(running )
{
// Get time and mouse position
//t = glfwGetTime();
//glfwGetMousePos( &x, NULL );

// Get window size (may be different than the requested size)
//glfwGetWindowSize( &width, &height );
//height = height > 0 ? height : 1;

// Set viewport
glViewport( 0, 0, width, height );

// Clear color buffer
glClearColor( 1.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );

 

// Swap buffers
glfwSwapBuffers();

// Check if the ESC key was pressed or the window was closed
running = !glfwGetKey( GLFW_KEY_ESC ) &&
 glfwGetWindowParam( GLFW_OPENED );
}

// Close OpenGL window and terminate GLFW
glfwTerminate();

exit( EXIT_SUCCESS );
}


It compiles but when I open it in chrome nothing happens.There is a message "Running" and black stripe.

Jukka Jylänki

unread,
Mar 8, 2014, 12:18:32 PM3/8/14
to emscripte...@googlegroups.com
Yeah, this has the same issue as described in the previous mail - the blocking modal while(running) loop is not supported, but you should use emscripten_set_main_loop() instead.


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael IV

unread,
Mar 8, 2014, 12:47:31 PM3/8/14
to emscripte...@googlegroups.com
Yeah,that was the problem.But now I have another one.If I include #include <GLES2/gl2.h>
then compiler throws:

C:\Program Files (x86)\Emscripten\emscripten\1.12.0\system\include\GLES2/gl2.h:3
8:26: error:
      typedef redefinition with different types ('khronos_intptr_t' (aka 'long')

      vs 'ptrdiff_t' (aka 'int'))
typedef khronos_intptr_t GLintptr;
                         ^
C:\Program Files (x86)\Emscripten\emscripten\1.12.0\system\include\GL/glext.h:50
72:19: note:
      previous definition is here
typedef ptrdiff_t GLintptr;
                  ^
In file included from mainGLFW2.cpp:15:
C:\Program Files (x86)\Emscripten\emscripten\1.12.0\system\include\GLES2/gl2.h:3
9:26: error:
      typedef redefinition with different types ('khronos_ssize_t' (aka 'long')
      vs 'ptrdiff_t' (aka 'int'))
typedef khronos_ssize_t  GLsizeiptr;
                         ^
C:\Program Files (x86)\Emscripten\emscripten\1.12.0\system\include\GL/glext.h:50
73:19: note:
      previous definition is here
typedef ptrdiff_t GLsizeiptr;
                  ^
2 errors generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting


--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/1tPcbGwHzc4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael Ivanov
Independent Pixel Commander 
onlygraphix.com
Tel:+972 54 4962254

Jukka Jylänki

unread,
Mar 8, 2014, 1:01:40 PM3/8/14
to emscripte...@googlegroups.com
You are mixing GLES2 ( \system\include\GLES2/gl2.h )  and desktop GL ( \system\include\GL/glext.h )  headers, that's a big no go! Make sure you include only GLES2 headers when building for Emscripten, if you are planning to stay clear of any emulation paths. If you are converting a desktop GL sample to build for Emscripten, the simplest is to probably #ifdef the native and web cases, so that you don't include desktop GL headers when doing the Emscripten build.

Michael IV

unread,
Mar 8, 2014, 2:25:05 PM3/8/14
to emscripte...@googlegroups.com

The thing is I don't include that header. It's probably gets included with GLFW or something like that.

Michael IV

unread,
Mar 10, 2014, 7:23:32 AM3/10/14
to emscripte...@googlegroups.com
Let me ask it again slightly differently.I see that Emscripten allows usage of GLFW right? Fine.I use it.But then I need also GLES2 headers to use the actual OpenGL API calls?So I include that header and getting those errors.which come from glext.h which is probably used by GLFW.So how do I use GLFW and GLES2 headers so that Emscripten can eat those? Btw,for the demo I I used GLFW headers from Emscripten SDK.

Alternatively,if I got you right,I can just use GLEW within OpenGL 3.2 core profile limits and only adjusting shaders syntax to that of GLES2?

Thanks.

Jukka Jylänki

unread,
Mar 10, 2014, 9:43:04 AM3/10/14
to emscripte...@googlegroups.com
It might be the case that our GLFW support doesn't work for pure WebGL/GLES2 use, but has only been used when emulating legacy desktop GL. Can anyone who is using GLFW with Emscripten confirm this? I see from here \http://www.glfw.org/docs/latest/news.html#news_30_gles that GLES2 support was added as new to GLFW 3.0. The GLFW headers in Emscripten https://github.com/kripken/emscripten/blob/master/system/include/GL/glfw.h mentions that they're from GLFW 2.7. 

Using GLEW might skip this specific problem, since looking at Emscripten GLEW headers https://github.com/kripken/emscripten/blob/master/system/include/GL/glew.h#L27 , it does have a specific #define GLEW_USE_LIB_ES20 to pass here. Perhaps you will need to add that in your build if you are going the GLEW route.

The paths that I do know of that support non-emulated WebGL/GLES2 are the following:
  - Init via SDL: see SDL documentation, or a test suite example, e.g. https://github.com/kripken/emscripten/blob/master/tests/sdl_canvas_alpha.c#L10

The last two are probably not that recommendable, since GLUT is not open source (I don't know what our status of FreeGLUT is), and X11 is extremely partial, just bare minimum has been hacked in to build some existing samples.

Michael IV

unread,
Mar 29, 2014, 11:33:16 AM3/29/14
to emscripte...@googlegroups.com
Ok,that is a useful info.So when do you add  a support for GLFW3 ?
Reply all
Reply to author
Forward
0 new messages