Can opengl work in Win32 console application?

My program is a Win32 console application.

But I want to do the belows for COLLISION DETECTION in my program:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(pos.x, pos.y, pos.z);
float mat2[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat2);

But it seems can’t work!

Can anyone help me?Thanks a lot!!!

Hi !

Could you be a little bit more specific about the problem, do you get an error or incoreect result or what ? (I guess you don’t have an active rendering context)

From an OpenGL point of view there is no difference between a console and a window application, the only difference is that the console application opens a console window, but a normal window application can do this also.

BUT, you do need to create a window or a bitmap to hook up the rendering context to, because you cannot execute any opengl functions without selecting a valid rendering context first.

Mikael

I am doing a online multiplayers game.

The server program is a Win32 console program, it will not have any rendering part, it just use for receiving and sending message to client and COLLISION DETECTION. It will just open a normal console window to printf the message.

For collision detection, it needs to run following:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(pos.x, pos.y,pos.z);
glRotatef(Players.at(1)->angle,0,1,0);
glRotatef(-90, 1, 0, 0);
float mat3[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mat3);
model2->setTransform(mat3);

BOOL collision1=model->collision(model2);

But, I find that it can’t detect the collision. But It works fine in my client program (which have rendering part)

So, I asked whether in my server.cpp can’t run the gl function, although it can compile.

OpenGL is for rendering.

What you’re doing there is basic matrix manipulation. Just do it yourself. Why use OpenGL for something that has nothing to do with rendering?

If you’re stubborn and insist on using OpenGL, the answer has already been given: you need a valid GL context, and for that you need a window.