Archived

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

Where is my triangle

This topic is 5093 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 am having a problem displaying a triangle, here is the code: #define WIN32_LEAN_AND_MEAN #include #include #include HDC HHDC; void SetUpPixelFormat(HDC Hdc) { int PixelFormat; static PIXELFORMATDESCRIPTOR PFD; PFD.nSize=sizeof(PIXELFORMATDESCRIPTOR); PFD.cColorBits=16; PFD.iPixelType=PFD_TYPE_RGBA; PFD.cDepthBits=16; PFD.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER; PFD.nVersion=1; PFD.iLayerType=PFD_MAIN_PLANE; PixelFormat=ChoosePixelFormat(Hdc,&PFD); SetPixelFormat(Hdc,PixelFormat,&PFD); } HRESULT CALLBACK WindowProc(HWND Hwnd,UINT Message, WPARAM WParam,LPARAM LParam) { int Height; int Width; HDC Hdc; HGLRC HGlRc; PAINTSTRUCT PaintStruct; switch(Message) { case WM_CREATE: Hdc=GetDC(Hwnd); HHDC=Hdc; SetUpPixelFormat(Hdc); HGlRc=wglCreateContext(Hdc); wglMakeCurrent(Hdc,HGlRc); return 0; break; case WM_CLOSE: wglMakeCurrent(Hdc,NULL); PostQuitMessage(0); return 0; break; case WM_PAINT: Hdc=BeginPaint(Hwnd,&PaintStruct); EndPaint(Hwnd,&PaintStruct); break; case WM_SIZE: Width=LOWORD(LParam); Height=HIWORD(LParam); if(Height==0) {Height=1;} glViewport(0,0,Width,Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(0,(float)(Width)/(float)(Height),1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return 0; default: break; } return (DefWindowProc(Hwnd,Message,WParam,LParam)); } int WINAPI WinMain(HINSTANCE HInstance,HINSTANCE PrevInstance,LPSTR LpCmdLine,int nShowCmd) { HWND Hwnd; MSG Message; WNDCLASSEX WindowClass; bool Done; WindowClass.cbSize=sizeof(WNDCLASSEX); WindowClass.nostyle=CS_HREDRAW|CS_VREDRAW; WindowClass.lpfnWndProc=WindowProc; WindowClass.cbClsExtra=0; WindowClass.cbWndExtra=0; WindowClass.hInstance=HInstance; WindowClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); WindowClass.hCursor=LoadCursor(NULL,IDC_ARROW); WindowClass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); WindowClass.lpszMenuName=NULL; WindowClass.lpszClassName="Window Class"; WindowClass.hIconSm=LoadIcon(NULL,IDI_APPLICATION); if(!RegisterClassEx(&WindowClass)) return 0; Hwnd=CreateWindowEx(NULL,"Window Class","OpenGL Game Engine", WS_VISIBLE|WS_SYSMENU|WS_OVERLAPPEDWINDOW,100,100,700,700,NULL, NULL, HInstance, NULL); if(!Hwnd) return 0; ShowWindow(Hwnd,SW_SHOW); UpdateWindow(Hwnd); Done=false; while(!Done) { PeekMessage(&Message,Hwnd,NULL,NULL,PM_REMOVE); if(Message.message==WM_QUIT) { Done=true; } else { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-5.0f); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_TRIANGLES); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glEnd(); SwapBuffers(HHDC); TranslateMessage(&Message); DispatchMessage(&Message); } } return Message.wParam; } PROGAMERS

Share this post


Link to post
Share on other sites