Jump to content
  • Advertisement

Archived

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

Al Gorithm

Windows GL issue :

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

If you intended to correct an error in the post then please contact us.

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(){
glShadeModel(GL_SMOOTH);
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);
			glLoadIdentity();
			GLfloat Aspect = Width/Height;
			gluPerspective(45,Aspect,1,1000);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			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.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  InfUn.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
  InfUn.hCursor =  LoadCursor(NULL, IDC_CROSS);
  InfUn.cbClsExtra = 0;
  InfUn.cbWndExtra = 0;
  InfUn.hInstance = hInstance;
  InfUn.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);  
  InfUn.lpszMenuName = NULL;
  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.  
Since this is added days later, I doubt anyone will read
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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
quote:
Original post by Raduprv
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 this post


Link to post
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!

Thanks for all your help

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

Share this post


Link to post
Share on other sites
quote:
Original post by Ready4Dis
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 this post


Link to post
Share on other sites
quote:
Original post by Raduprv
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!