glGetString problem

ptitSeb

Serial Porter
Joined
Aug 15, 2012
Messages
8,453
Age
47
Location
France, near Lyon
Hi,

I'm having some difficulties with a simple call in GL. I must do something wrong, but cannot get what.

When doing glGetString to have vendor or extensions string, most of the time I have just 0 as string (sign of error, but what error?).

Here is a simple test program "test.c":


#include <GLES2/gl2.h>
#include <stdio.h>
 
int main(int argc, char* argv[])
{
printf("Test of GLES2\n");
 
const char *sVendor = glGetString(GL_VENDOR);
printf("Vendor = %s\n", sVendor);
const char *sVersion = glGetString(GL_VERSION);
printf("Version = %s\n", sVersion);
}

and compile it with


gcc test.c -o test -lGLESv2

I always get (null) as string. Even when putting -lGLES_CM or adding -lEGL, same.

The only change is when using libGL of lunixboch, vendor is still (null), but I have a text for Version.

*EDIT*, I have checked, glGetError return NO_ERROR.

What is wrong?
 
Last edited by a moderator:

crow_riot

Well-Known Member
Joined
Sep 21, 2009
Messages
1,763
Location
.at
i think a gl context must be initialized before. never had problems getting vendor strings
 

ptitSeb

Serial Porter
Joined
Aug 15, 2012
Messages
8,453
Age
47
Location
France, near Lyon
i think a gl context must be initialized before. never had problems getting vendor strings
Yes, maybe, but I suspect that can be a problem in many software (GLEW included). Many tried to have the "Extensions" string before creating the display, so that can be problematic!

I'll try some simple "create context" / delete context in my simple test.
 

ptitSeb

Serial Porter
Joined
Aug 15, 2012
Messages
8,453
Age
47
Location
France, near Lyon
Ok, I've create some context, and I've now some strings.

The sample program is now:

#include <GLES2/gl2.h>
#include <EGL/egl.h>
#include <stdio.h>
 
void print_gls(const char *str, const char *gls)
{
GLenum glerr;
if (gls) {
printf(str, gls);
} else {
glerr=glGetError();
printf("gl Error = ");
switch (glerr) {
case GL_NO_ERROR:
printf("NO_ERROR");
break;
case GL_INVALID_ENUM:
printf("GL_INVALID_ENUM");
break;
case GL_INVALID_VALUE:
printf("GL_INVALID_VALUE");
break;
case GL_INVALID_OPERATION:
printf("GL_INVALID_OPERATION");
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
printf("GL_INVALID_FRAMEBUFFER_OPERATION");
break;
case GL_OUT_OF_MEMORY:
printf("GL_OUT_OF_MEMORY");
break;
default:
printf("unknown");
}
printf("\n");
}
}
 
int main(int argc, char* argv[])
{
 printf("Test of GLES2\n");
 int maj, min;
 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
 
 if (!eglInitialize(d, &maj, &min)) {
  printf("eglinfo: eglInitialize failed\n");
 }
 printf("EGL v%i.%i initialized\n", maj, min);
 EGLint attribs[] =
 {
  EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  EGL_RED_SIZE, 1,
  EGL_GREEN_SIZE, 1,
  EGL_BLUE_SIZE, 1,
  EGL_NONE
 };
 EGLint ctx_attribs[] =
 {
 EGL_CONTEXT_CLIENT_VERSION, 2,
 EGL_NONE
 };
 
 
 EGLint num_configs;
 EGLConfig config;
 if (!eglChooseConfig(d, attribs, &config, 1, &num_configs) || (num_configs < 1))
 {
  printf("Could not find config for %s (perhaps this API is unsupported?)\n", "GLES2");
 }
 
 EGLint vid;
 if (!eglGetConfigAttrib(d, config, EGL_NATIVE_VISUAL_ID, &vid))
 {
  printf("Could not get native visual ID from chosen config\n");
 }
 eglBindAPI(EGL_OPENGL_ES_API);
 
 EGLContext ctx=eglCreateContext(d, config, EGL_NO_CONTEXT, ctx_attribs);
 EGLSurface srf=eglCreateWindowSurface(d, config, NULL, NULL);
 
 if (!eglMakeCurrent(d, srf, srf, ctx))
 { 
  printf("eglMakeCurrent() failed\n");
 }
 
 const char *sVendor = glGetString(GL_VENDOR);
 print_gls("Vendor = %s\n", sVendor);
 const char *sVersion = glGetString(GL_VERSION);
 print_gls("Version = %s\n", sVersion);
 const char *sRenderer = glGetString(GL_RENDERER);
 print_gls("Renderer = %s\n", sRenderer);
 const char *sExtensions = glGetString(GL_EXTENSIONS);
 print_gls("Extensions = %s\n", sExtensions); 
 
 eglDestroySurface(d, srf); 
 eglDestroyContext(d, ctx);
 eglTerminate(d);
}
And you compile it with 

gcc test.c -o test -lGLESv2 -lEGL

Now I have a nice output. So now, I may have a solution for Rice plugin, and all GLEW software that fail at init (because nobody expect a simple glGetString to return null! )
 
Last edited by a moderator:

ptitSeb

Serial Porter
Joined
Aug 15, 2012
Messages
8,453
Age
47
Location
France, near Lyon
Hum, maybe I also miss a little


eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);


before the eglDestroy...
 
Last edited by a moderator:

mcobit

Advanced Member
Joined
Jul 28, 2008
Messages
6,910
Hum... so this was the problem with TileMassacreSHMUP, too?


Good that you found a solution :)


Awaiting pnd ... ;)
 
Last edited by a moderator:

ptitSeb

Serial Porter
Joined
Aug 15, 2012
Messages
8,453
Age
47
Location
France, near Lyon
Hum... so this was the problem with TileMassacreSHMUP, too?


Good that you found a solution :)


Awaiting pnd ... ;)
Not sure, I think I have another problem with this one. Just adding a "SDL_Init" 1st line in main make it hang, so I have something wrong with the linker or something like that. I'm play with muppen for now (because gthumb p**s me off, the slideshow works, but hang at the exit, veeeery anoying).
 
Top