Når jeg køre mit opengl program får jeg ingen fejlmeddelser, men der skulle være kommet en trekant som ikke er kommet og den arbejder HELE tiden hvis jeg tager markøren ind over vinduet kommer der bare et timeglas(arbejdstegn)!
Ved godt min kode er lidt lang, men hved ikke hvor i koden det går gjaldt her er min kode:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
float angle = 0.0f;
HDC g_HDC;
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat;
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|
PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0,0,0,0,0,0,
0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,0,0};
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC,nPixelFormat, &pfd);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC;
static HDC hDC;
int width,height;
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_SIZE:
height = HIWORD(lParam);
width = LOWORD(lParam);
if (height = 0)
{
height = 1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 0;
break;
default:
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
bool done;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.lpfnWndProc = WndProc;
windowClass.style = CS_HREDRAW|CS_VREDRAW;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.hIcon = LoadIcon(NULL,IDI_HAND);
windowClass.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
windowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "MyClass";
if(!RegisterClassEx(&windowClass))
{
return 0;
}
hwnd = CreateWindowEx(
NULL,
"MyClass",
"Mit første vindue efter OPENGL GAME PROGRAMMING",
WS_OVERLAPPED|WS_VISIBLE|WS_SYSMENU,
0,0,
300,300,
NULL,
NULL,
hInstance,
NULL);
if(!hwnd)
{
return 0;
}
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
done = FALSE;
while(!done)
{
PeekMessage(&msg,NULL,0,0,PM_REMOVE);
if(msg.message == WM_QUIT)
{
done = TRUE;
}
else
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angle = angle + 0.1f;
if(angle>= 360.0f)
{
angle=0.0f;
}
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(angle,0.0f,0.0f,1.0f);
glColor3f(1.0f,0.0f,0.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(g_HDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}