Advertisement

Why doesnt this code work?

Started by June 10, 2002 04:55 PM
2 comments, last by Darobat 22 years, 8 months ago
Ok... This is my first time using OpenGL and My code doesn't work... Could someone pleas help me! ---------------CODE---------------CODE---------------CODE------- #include <windows.h> #include <gl/gl.h> LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; HWND hWnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit; wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "Darobats First GL"; RegisterClass(&wc); hWnd = CreateWindow("FGL", "Darobats First OpenGL", WS_CAPTION|WS_POPUPWINDOW|WS_VISIBLE, 0, 0, 256, 256, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, TRUE); while(!bQuit) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5, 0.0f, -6.0f); glBegin(GL_TRIANGLES); glVertex3f(0.0f, 1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); glEnd(); } } DestroyWindow(hWnd); wglMakeCurrent( NULL, NULL ); wglDeleteContext( hRC ); ReleaseDC( hWnd, hDC ); return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CLOSE: PostQuitMessage( 0 ); return 0; case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: PostQuitMessage(0); return 0; } return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } [edited by - Darobat on June 10, 2002 5:58:07 PM]
--------------------C++ Home - Check it out!Lol... - Amazing video
Im not very familiar with windows window handling .. but if its double buffered youre missing a SwapBuffers( ... );
Advertisement
Your class names are different, they must be the same.

ie.

"Darobats First GL" should become "Darobats First OpenGL" or vice versa

wc.lpszClassName = "Darobats First OpenGL";
...
hWnd = CreateWindow("FGL", "Darobats First OpenGL", WS_CAPTION|WS_POPUPWINDOW|WS_VISIBLE,
0, 0, 256, 256,
NULL, NULL,
hInstance, NULL);

Oops, I mean "FGL" not "Darobats First OpenGL"

[edited by - sibbo2001 on June 10, 2002 6:19:53 PM]
1. You create your window class and register it as "Darobats First Gl" and then when you create your window you use "FGL" as the class name.

2. I don''t see that you initialized opengl and set up the rendering context and pixel format or anything.

3. You don''t check the return values of your function calls.

4. Style: You don''t initialize your bQuit variable to false before your enter your message loop.

Since this was posted on the NeHe message board I''d recommend looking through his tutorials.

Kory

This topic is closed to new replies.

Advertisement