#### Archived

This topic is now archived and is closed to further replies.

# Windows GL issue :

This topic is 5309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I recently purchased "OpenGL Game Programming" to port my graphics engine from GLUT to windows OpenGL (note : Linux, mac, etc. ports will come). I made a test application in MS Visual C++ based off the content in Chapter 2, but I'm having a problem : the test app compiles without error, but the application contains only a blank screen. Can someone please help me determine the problem? If it helps, here's the test program's source (abridged):
GLfloat Width = 640;
GLfloat Height = 480;
HDC g_HDC;

void SetupPixelFormat(HDC hDC){
int nPixelFormat;
static PIXELFORMATDESCRIPTOR InfUn;
InfUn.nSize = sizeof(PIXELFORMATDESCRIPTOR);
InfUn.nVersion = 1;
InfUn.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
InfUn.iPixelType = PFD_TYPE_RGBA;
InfUn.cColorBits = 16;
InfUn.cDepthBits = 16;
InfUn.iLayerType = PFD_MAIN_PLANE;
nPixelFormat = ChoosePixelFormat(hDC, &InfUn);
SetPixelFormat(hDC, nPixelFormat, &InfUn);
}

void Render(){
glTranslatef(0.0,0.0,-5.0);
glBegin(GL_TRIANGLES);
glColor3i(1,0,0);
glVertex3f(0,0,0);
glColor3i(0,1,0);
glVertex3f(1,0,0);
glColor3i(0,0,1);
glVertex3f(1,1,0);
glEnd();
SwapBuffers(g_HDC);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
static HDC hDC;
static HGLRC hRC;
switch(message){
case WM_CREATE : {hDC = GetDC(hwnd);
g_HDC = hDC;
SetupPixelFormat(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
return 0;
break;}
case WM_CLOSE  : {wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
PostQuitMessage(0);
return 0; break;}
case WM_PAINT  : {hDC = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps); return 0 ; break;}
case WM_SIZE : {if(Height = 0){Height = 1;}
else{}
Height = HIWORD(lParam);
Width = LOWORD(lParam);
glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
GLfloat Aspect = Width/Height;
gluPerspective(45,Aspect,1,1000);
glMatrixMode(GL_MODELVIEW);
return 0;
break;
}
}
return DefWindowProc(hwnd, message, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
WNDCLASSEX InfUn;
HWND hwnd;
MSG msg;
bool Active = true;
InfUn.cbSize = sizeof(WNDCLASSEX);
InfUn.lpfnWndProc = WndProc;
InfUn.style = CS_HREDRAW | CS_VREDRAW;
InfUn.cbClsExtra = 0;
InfUn.cbWndExtra = 0;
InfUn.hInstance = hInstance;
InfUn.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
InfUn.lpszClassName = "InfUn1";
RegisterClassEx(&InfUn);
hwnd = CreateWindowEx(NULL,
"InfUn1",
"Inflicted Unity",
WS_OVERLAPPEDWINDOW,
150,150,
Width, Height,
NULL, NULL,
hInstance,
NULL);

ShowWindow(hwnd, SW_SHOWMAXIMIZED);
UpdateWindow(hwnd);

while(Active){
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if(msg.message == WM_QUIT){
Active = false;
}
else{
Render();
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
/*yes, I know this is inefficient source, but
this is a test application intended for experimentation
before I port my engine, rather than a serious venture.
this.  I just added it for fun.
::sings meow mix song::
BTW, I will be posting some screenshots from one of my
engines (I'm developing four currently) hopefully in a
couple months, as soon as OpenGL 2.0 is released, as my
engine is essentially crap without it. . . when you see
it you'll shit. . . that is, if you can be impressed
by photorealistic teapots, as we have no 3d artists anymore. . . :(  Textures rock though :)
*/

I would appreciate any assistance in this matter. Thank you. [edited by - Al Gorithm on June 4, 2003 3:23:21 PM] [edited by - Al Gorithm on June 4, 2003 3:25:45 PM] [edited by - Al Gorithm on June 5, 2003 10:57:57 PM]

##### Share on other sites
Are you sure the screen is blank? Your colors are going to be awefully dim. The values with glColor3i range from 0 to 255. 1 is barely on the scale. Perhaps you meant to use glColor3f? In that case, 1 would be fully on.

##### Share on other sites
Shit.
That was it, thank you.
Always the dumbest thing. . .

##### Share on other sites
If you want to port your application, use SDL instead. It will work on Windows and other OSes too. And it is fairly simple to use, and gives you other things as well, such as keyboard and mouse handling, etc.

Height Map Editor | Eternal Lands | Fast User Directory

##### Share on other sites
quote:
If you want to port your application, use SDL instead. It will work on Windows and other OSes too. And it is fairly simple to use, and gives you other things as well, such as keyboard and mouse handling, etc.

Height Map Editor | Eternal Lands | Fast User Directory

He WAS using GLUT, which is similar in concept to SDL for opengl... GLUT is also portable (I know they have windows, linux, and I think beos and mac also).

##### Share on other sites
To top it all off, I made a dumb mistake by not loading the Identity Matrix so the triangle for some reason seemed to "shrink" every frame. D'OH!

[edited by - Al Gorithm on June 4, 2003 4:27:28 PM]

##### Share on other sites
No problem, even though I didn''t actually help contribute to solving your problems .

##### Share on other sites
quote:
He WAS using GLUT, which is similar in concept to SDL for opengl... GLUT is also portable (I know they have windows, linux, and I think beos and mac also).

I know what GLUT is, but Glut is dead, and SDL does pretty much what Glut does, plus more.

Height Map Editor | Eternal Lands | Fast User Directory

##### Share on other sites
Glad to help! Been there, did that.

##### Share on other sites
quote:
I know what GLUT is, but Glut is dead, and SDL does pretty much what Glut does, plus more.

He said he wanted to port to Windows OpenGL, and NOT use GLUT. Using SDL would not be any different than using GLUT, that was my point. It would not bring him any closer to doing the windows code himself, which is what he is/was trying to do.

##### Share on other sites
My test application is working perfectly, and I was getting ready to put it aside to start porting my engine, but there are a few remaining things I would like to ask . . . "OpenGl Game Programming" does certain things a way I''m not used to . . . and I don''t understand why it is done this way. Can someone please explain? Thanks.

1) I don''t understand why the Devmode stuff is used for fullscreen mode when (to me) there is no discernable difference between than and a maximized popup window. Is it all "under the hood" stuff with the display device? The text certainly implies this with ". . . which contains information about the devic initialization and environment of an output device" If so, can someone please tell me what exactly this does? Thanks.

2) The AdjustWindowRectEx() function - I am unable to tell a difference between my application including this function and without. . . the book says it calculates the required size of window rectangle, based off the desired client-rectangle size. It says additionally that the window borders will not overlap the rendering area. I compiled my test application with this function included, but notice no difference . . .

Christopher Pugh

##### Share on other sites
1) If you just use a window, you only have access to whatever display mode the desktop is in. If you want a 32-bit mode and the desktop is in 16-bit mode, you''re out of luck with a windowed app.

2) The AdjustWindowRectEx takes into account extra window decorations like the title bar, borders, menu, etc. When you create a window, the values you specify are for the whole window, including the decorations. The AdjustWindowRectEx gives you a size that accounts for the decorations and results in a client area that is the desired width and height.

AdjustWindowRectEx doesn''t change the window size. It just gives you a rectangle that you can use with a MoveWindow call to resize the window (or pass to the CreateWindow function, if it hasn''t been called. I don''t remember which way the book does it - Adjust/Create or Create/Adjust/Move.)

Hope that helps!