I've been working with opengl for several weeks now, i stumbled upon an
issue. I'm using glut & MS Visual C++, and I can't seem to use
glWindow2i method. Then I've tried MesaGLUT, included <GL/glew.h>...
Then, I get an
error LNK2001: unresolved external symbol __imp____glewWindowPos2i
It maybe has to do something with including or VC++ dependencies hence
the "unresolved external"... I don't know...
Can you help me? :)
How about actually linking against GLEW. Just including glew.h won't do the
trick. You also must add glew.lib to the libraries you link against in your
linker settings.
--
OpenGL tip #42:
How to exactly map texture texels to screen pixels:
<http://preview.tinyurl.com/cgndc8>
If you're using Mesa 3D Graphics Library and VC++, and need to use
glWindowPos2i you need to use the
OpenGL extension mechanism to get a pointer to the specified function,
ie. wglGetProcAddress("glWindowPos2i");
Instead of GL/glew.h, you can use:
#include <GL/mesa_wgl.h>
#include <GL/wglew.h>
After that include, insert this line:
typedef void (WINAPI *WINPOS)(int x, int y);
And finnaly, before using glWindowPos2i func. declare and initialize
the function:
WINPOS glWindowPos2i;
glWindowPos2i = (WINPOS)wglGetProcAddress("glWindowPos2i");
There is no need for extra linker settings.
Seems like glew.lib did not came with Mesa, anyway, I've downloaded the
lib file, pasted it to lib and the error is gone.. However, when I run
the app it crashes...
Thank you for your solution beaver, it works fine for me. But I'm
looking for more elegant solution like Wolfgang is offering, so my
friends that use Linux can also compile this.
Wolfgangs solution is syntacticly ok, but application crashes on
glWindowPos2i
You can use compiler macros for that purpose.
You must check that an extension is really available at runtime before
using it. GLEW will initialize unsupported extension entry points to
null (which is probably why your program crashes), so you can just check
that instead of parsing the GL_EXTENSIONS string if you like.
--
John Tsiombikas (Nuclear / Mindlapse)
http://nuclear.sdf-eu.org/
>> You must check that an extension is really available at runtime before
>> using it. GLEW will initialize unsupported extension entry points to
>> null (which is probably why your program crashes), so you can just
check
>> that instead of parsing the GL_EXTENSIONS string if you like.
>>
>>
> Ok, cool, and how exactly would I do that?
By checking the function pointer for (not) being null.
if(glWindowPos2i) {
glWindowPos2i(...);
} else {
fprintf(stderr, "glWindowPos2i not supported\n");
return;
}
You can also implement a small generic placeholder function, emitting an
informative message, which address you place in uninitialized GLEW
function pointers. Not that such a function _must_ exit the program, if
it's used to fill in for functions that return a value.
If your runtime environment implements some backtrace functionality one
can also print nice debug information. Example with GNU glibc:
void not_implemented(...)
{
#define MAX_CALL_DEPTH 1000
void *callptrs[MAX_CALL_DEPTH];
int calldepth;
calldepth = backtrace(callptrs, MAX_CALL_DEPTH);
fprintf(stderr, "Unimplemented function called - Backtrace, last
call first:\n");
backtrace_symbols_fs(callptrs, calldepth, stderr);
fflush(stderr);
_exit(-1); /* IMPORTANT: Use the underscore exit for immediate
process termination */
}
void init_GL_ext()
{
/* ... */
if(!glWindowPos2i)
glWindowPos2i = not_implemented();
}
Wolfgang
The provided solution (using compiler macros) is working very fine,
but anyway, there are some other possible solutions.
The interesting solution on specified problem can be find here:
https://svn.assembla.com/svn/LaspView/src/SpiceRender/glWindowPos.cpp
so, check it out!
Cheers