tags:

views:

166

answers:

3

Given that I am programming within another program already using OpenGL (let's say theoretically that I have no idea how they are using it).

Can I just set up my context however I want and push/pop it from the stack and all should work as expected, or MUST I know how my (calling) program is using OpenGL in order to avoid accidentally screwing things up?

Also, how would I go about "initializing" OpenGL when it might have already been initialized?

Thanks for any advice you might have!

A: 

I am told that theoretically OpenGL should be able to work within any context as long as you restore the prior context afterwards.

A: 

To answer your first question, you probably could get away with calling glPushAttrib(GL_ALL_ATTRIB_BITS) before calling the program's functions, and calling glPopAtrib() afterward. Note that this can be slow if you do it frequently (say, every frame in a loop).

I'm not sure what you mean by initializing OpenGL. Do you mean setting up the rendering context? Setting viewport and projection? Disabling or enabling certain features? You can always check if certain states are enabled (using glGet functions), but the rest depends on how your program and the other program work.

Firas Assaad
A: 

What exactly do you want to do with OpenGL? Are you trying to draw into the same window? Do you want to draw into your own window? If you want to just draw into your own window, and the fact that the existing app uses OpenGL is just a coincidence, then you can probably get away with just creating a completely new context and ignoring the existing stuff. The only gotcha is that you will need to make the existing context current whenever you finish what you are doing, and make your context current whenever you want to do something with it. The existing code won't be expecting to need to make its own context current, and may wind up randomly drawing into your context if you aren't careful.

If you want to draw into the existing window, then your use almost certainly requires some sort of idea about what the existing stuff is doing.

wrosecrans