GlGetError issues
Find out issue when compiling this piece of a test case with the latest GL4ES (SDL2 based):
/*This source code copyrighted by Lazy Foo' Productions (2004-2019)
and may not be redistributed without written permission.*/
//Using SDL, SDL OpenGL, standard IO, and, strings
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <GL/GLU.h>
#include <stdio.h>
#include <string>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
//Starts up SDL, creates window, and initializes OpenGL
bool init();
//Initializes matrices and clear color
bool initGL();
//Input handler
void handleKeys( unsigned char key, int x, int y );
//Per frame update
void update();
//Renders quad to the screen
void render();
//Frees media and shuts down SDL
void close();
//The window we'll be rendering to
SDL_Window* gWindow = NULL;
//OpenGL context
SDL_GLContext gContext;
//Render flag
bool gRenderQuad = true;
bool init()
{
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Use OpenGL 2.1
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
//Create window
gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
if( gWindow == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create context
gContext = SDL_GL_CreateContext( gWindow );
if( gContext == NULL )
{
printf( "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Use Vsync
if( SDL_GL_SetSwapInterval( 1 ) < 0 )
{
printf( "Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError() );
}
//Initialize OpenGL
if( !initGL() )
{
printf( "Unable to initialize OpenGL!\n" );
success = false;
}
}
}
}
return success;
}
bool initGL()
{
bool success = true;
GLenum error = GL_NO_ERROR;
//Initialize Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
//Check for error
error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
success = false;
}
//Initialize Modelview Matrix
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//Check for error
error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
success = false;
}
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );
//Check for error
error = glGetError();
if( error != GL_NO_ERROR )
{
printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
success = false;
}
return success;
}
void handleKeys( unsigned char key, int x, int y )
{
//Toggle quad
if( key == 'q' )
{
gRenderQuad = !gRenderQuad;
}
}
void update()
{
//No per frame update needed
}
void render()
{
//Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
//Render quad
if( gRenderQuad )
{
glBegin( GL_QUADS );
glColor3f( 1.0f, 0.0f, 0.0f );
glVertex3f( -0.5f, -0.5f, 0.0f );
glColor3f( 0.0f, 1.0f, 0.0f );
glVertex3f( 0.5f, -0.5f, 0.0f );
glColor3f( 0.0f, 0.0f, 1.0f );
glVertex3f( 0.5f, 0.5f, 0.0f );
glVertex3f( -0.5f, 0.5f, 0.0f );
glEnd();
}
}
void close()
{
//Destroy context
SDL_GL_DeleteContext( gContext );
gContext = NULL;
//Destroy window
SDL_DestroyWindow( gWindow );
gWindow = NULL;
//Quit SDL subsystems
SDL_Quit();
}
int main( int argc, char* args[] )
{
//Start up SDL and create window
if( !init() )
{
printf( "Failed to initialize!\n" );
}
else
{
//Main loop flag
bool quit = false;
//Event handler
SDL_Event event;
//Enable text input
SDL_StartTextInput();
//While application is running
while( !quit )
{
while ( SDL_PollEvent(&event) ){
switch(event.type){
case SDL_QUIT:
quit = true;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
quit = true;
break;
}
break;
}
}
//Render quad
render();
//Update screen
SDL_GL_SwapWindow( gWindow );
}
//Disable text input
SDL_StopTextInput();
}
//Free resources and close SDL
close();
return 0;
}
It just says now "Unable to initialize OpenGL". That error is the first one from initGL().
I tracked it down to this commit https://github.com/ptitSeb/gl4es/commit/7d233580a46ff572acb1446ba55231827ce8cc17 , called "Changed how glGetError works, should be consistent with OpenGL book now".
Not sure if it error with the test case arise, or in gl4es change from this commit? Previous to that commit all works fine, exactly this change starts to causing error to react differently and fail with such test case
Problem I see with that sample is that it doesn't purge GL error before setting the glMatrix... So if there was some error durring SDL2 init, it will exit with error.
In initGL() change GLenum error = GL_NO_ERROR; with GLenum error = glGetError(); to purge the GL error, and I think it will work better.
If it works, it would be interresting to see what function error out in SDL init.
With initGL() change GLenum error = GL_NO_ERROR; with GLenum error = glGetError(); it works ! Is it mean that SDL init errors somehow ? But then why/where ?
I have no idea! You need to track the error yourself.
But you think it surely not gl4es ? I mean, before if work just by some luck , and once gl4es was changes to have better glerror() handling other errors show ups ? Just need to be sure it 100% no gl4es, so i can dig in into SDL code :)
Yeah, I tested it on the Pandora, with latest GL4ES, and it worked fine, no error on my side. So yeah, sorry, it's on AmigaOS side.
Much Thanks for the library.
On Sat, Apr 17, 2021, 08:56 ptitSeb @.***> wrote:
Problem I see with that sample is that it doesn't purge GL error before setting the glMatrix... So if there was some error durring SDL2 init, it will exit with error.
In initGL() change GLenum error = GL_NO_ERROR; with GLenum error = glGetError(); to purge the GL error, and I think it will work better. If it works, it would be interresting to see what function error out in SDL init.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ptitSeb/gl4es/issues/295#issuecomment-821826649, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASUB45LMN655M4OKQOEI5BDTJGHR5ANCNFSM43DC7KLA .