I am trying to draw a custom opengl overlay (steam does this, for example) in a 3D board game. This overlay should basically be able to display the state of some variables that the user can influence by pressing some keys. Think of it like a game coach. The goal, first of all, is to draw a few primitives at a specific point on the screen. Later, I want the game window to have a slightly nice “gui” component. The game uses the SwapBuffers method from GDI32.dll. Currently, I can enter a custom DLL file into the game and enable the SwapBuffers method. My first idea was to insert an overlay pattern into this function. This can be done by switching the 3D drawing mode from the game to 2d, then draw a 2d overlay on the screen and turn it back on, for example:
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glOrtho(0.0, 640, 480, 0.0, 1.0, -1.0);
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex2f(0, 0);
glVertex2f(0.5f, 0);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.0f, 0.5f);
glEnd();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
SwapBuffers_OLD(HDC);
.
- , ( 3d-2d)?
- , - . ( - opengl - ,
...?)
- SwapBuffers ?
, - .
, , 1.6, .
.
EDIT:
, opengl, "derHass". :
GLboolean gdiSwapBuffersHOOKED(HDC hdc) {
HGLRC oldContext = wglGetCurrentContext();
if (!contextCreated) {
thisContext = wglCreateContext(hdc);
wglMakeCurrent(hdc, thisContext);
initContext();
}
else {
wglMakeCurrent(hdc, thisContext);
}
drawContext();
wglMakeCurrent(hdc, oldContext);
return gdiSwapBuffersOLD(hdc);
}
GLvoid drawContext() {
glColor3f(1.0f, 0, 0);
glBegin(GL_QUADS);
glVertex2f(0,190.0f);
glVertex2f(100.0f, 190.0f);
glVertex2f(100.0f,290.0f);
glVertex2f(0, 290.0f);
glEnd();
}
GLvoid initContext() {
contextCreated = true;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 640, 480, 0.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0, 0, 0, 1.0);
}
:
cs
, , ..
.