glWindowPos2f( ) Question

I am working on a project in VIsual Studio 2003 that uses Qt for the GUIs and OpenGL. I am currently using Qt 4.3.0 and am running into some problems using my glRasterPos2f( ) call. I think I am doing some conversion from window coordinates to my ortho coordinates incorrectly, and I was flipping through the red book when I discovered the function glWindowPos2f( ). I figured I should try and use this function since all my original numbers are in window coordinates. Unfortunately, when I try and compile, it says it knows nothing of the function. This is the only OpenGL function I have had it not recognize and I was wondering if anybody here knows what version of OpenGL Qt is using or what I need to add to be able to use glWindowPos2f( ). Thanks!

Edited Portion:
I ran a glGetString( GL_VERSION ) on my code to see what version of OpenGL I am using. It returns to me NULL. My code looks like this to check it.

OpenGL Version = (null)
Did I do the glGetString incorrectly or what is wrong? Does this mean I don’t have any OpenGL installed and that the OpenGL I am using is all being given to me by Qt? Thanks!

  1. glGetString issue:
    Make sure you have an OpenGL context created before any gl* call.

  2. glWindowPos2f() issue:
    If you go through the appendices of the OpenGL spec,
    you’ll at section G.14 that this kind of function
    is a core feature of OpenGL 1.4. If your driver version is less than 1.4, you have to use extension
    GL_ARB_window_pos. Remember that Visual studio provides an OpenGL 1.1 header file, anything else has to be detected at runtime and loaded. For this purpose you can use
    glew or do it yourself (by getting some tutorial on the web or studying the source code of glew).

I have never used extensions before, so how do I try and call GL_ARB_window_pos? Is it just a function with the same arguments or what? Thanks!

An extension is a set of additional features to a given OpenGL version.

Each extension can define new tokens (macros), new functions or just new features.

For instance extension ARB_texture_non_power_of_two tells you can use non-power-of-two textures but it does not add new tokens or functions.

Extensions are all listed here:
http://www.opengl.org/registry

The extension you are interested in is described here:

http://www.opengl.org/registry/specs/ARB/window_pos.txt

This extension defines the following functions:

void WindowPos2dARB(double x, double y)
void WindowPos2fARB(float x, float y)
void WindowPos2iARB(int x, int y)
void WindowPos2sARB(short x, short y)

void WindowPos2dvARB(const double *p)
void WindowPos2fvARB(const float *p)
void WindowPos2ivARB(const int *p)
void WindowPos2svARB(const short *p)

void WindowPos3dARB(double x, double y, double z)
void WindowPos3fARB(float x, float y, float z)
void WindowPos3iARB(int x, int y, int z)
void WindowPos3sARB(short x, short y, short z)

void WindowPos3dvARB(const double *p)
void WindowPos3fvARB(const float *p)
void WindowPos3ivARB(const int *p)
void WindowPos3svARB(const short *p)

Look at this document http://glew.sourceforge.net/basic.html to learn how to use glew with the extension you want.

In your case the code should look like:

#include <GL/glew.h>
GLenum err = glewInit();
if (err == GLEW_OK)
{
 if (GLEW_VERSION_1_4)
 {
  glWindowPos2f( );
 }
 else if(GLEW_ARB_window_pos)
  {
  glWindowPos2fARB( );
  }
}

… just a guess from the doc.