OpenGL's glDrawRangeElements not working on Windows/freeglut?

Started by
1 comment, last by dave j 11 years, 7 months ago
Hello everyone, still pretty new feeling for opengl here. Using freeglut for Windows, I've been getting an error for code that was working in my Linux build. My makefile code includes the following for importing webgl stuff:


ifeq ($(shell uname), Linux)
Graphics = -I/usr/X11R6/include -L/usr/X11R6/bin -lglut -lGL -lGLU
else ifeq ($(shell uname), Darwin) # Darwin = Mac
Graphics = -framework OpenGL -framework GLUT
else
Graphics = -I ".\include" -L ".\lib" -lglut -lGLU -lGL -lfreeglut -lglu32 -lopengl32 -Wl,--subsystem,windows -static
endif


where .\include and .\lib are just the folders from freeglut-MinGW-2.8.0-1.mp.zip, and my src folder has the freeglut dll inside. So, that said, this is the error I'm getting:


error: 'glDrawRangeElements' was not declared in this scope


due to this call:

glDrawRangeElements(GL_TRIANGLES, 0, 3, 6, GL_UNSIGNED_BYTE, indices+6*i);

So, Googling the error only gives one good Google result, and it's a cryptic dead link reply along with, using glext.h, the following:


PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements = NULL;
glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)wglGetProcAddress("glDrawRangeElements");


So I tried #include glext.h with the file in my src folder, and it tells me glDrawRangeElements doesn't have a type.

error: 'glDrawRangeElements' does not name a type

Surprisingly, tweaking the above code makes the error go away by removing the middle step:

PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)wglGetProcAddress("glDrawRangeElements");


But when it finally gets to the display of the game, if any instances of glDrawRangeElements are left, it just gives a blank white screen. Commenting out those instances of glDrawRangeElements makes everything except for that work, but trying to include them breaks everything.

Another, unrelated Google result brought this code up:


#ifdef _WIN32
// function pointer to OpenGL extensions
// glDrawRangeElements() defined in OpenGL v1.2 or greater
PFNGLDRAWRANGEELEMENTSPROC pglDrawRangeElements = 0;
#define glDrawRangeElements pglDrawRangeElements
#endif


along with


#ifdef _WIN32
// get function pointer to glDrawRangeElements
glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)wglGetProcAddress("glDrawRangeElements");
#endif


But I'm basically getting the same errors. If I assign anything to glDrawRangeElements, it says pglDrawRangeElements does not name a type. I have glext.h included too, so this comes off as especially strange. So, any thoughts? I'm on a Windows 7 64-bit OS using OpenGL, GLU, and freeglut as far as I can tell.
Advertisement
Well, at the least, I found that this works with similar results:

glDrawRangeElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices+6*i);

Might be a bit laggier, not sure yet, but definitely runs on Windows and Linux both. Anyways, just posting this in case someone comes across this same issue!
Two things:

Windows's native OpenGL support is for an old version. To use the newer APIs you need to use wglGetProcAddress. Most people use an extension loading library for this and I notice that you are not linking with any. Details of extension loading libraries can be found here. They work on other platforms as well so you don't have to write conditional code.

The other thing is you are linking with the -static flag which will prevent linking with dynamic libraries - this might also cause problems.

This topic is closed to new replies.

Advertisement