Fix lige det her OpenGL shit !!!
Jeg sad forleden og skrev et lille OpenGL program. Koden er fra NeHe site, men jeg har lavet om på strukturen i koden (lavet nogle extra funktioner og sådan...) og nu virker shittet sgu ikke !!!Det vil overhovedet ikke tegne hverken trekanten eller firkanten, er der ikke en eller anden OpenGL hej der lige kan løse propblemet for mig ?
I skal ikke tage jer af de engelske kommentarer, jeg syntes bare det lyder bedre på engelsk end på dansk :-)
/////////////// KODE ///////////////
////////////////////////////////////////////////
// Ehh.. speeds up build...
#define WIN32_MEAN_AND_LEAN
////////////////////////////////////////////////
// Header files
#include <windows.h> // Standard Windows
#include <gl\\gl.h> // OpenGL32 Library
#include <gl\\glu.h> // Glu32 Library
#include <gl\\glaux.h> // Glaux Library
////////////////////////////////////////////////
// Global variables
HGLRC g_hRC=NULL; // Handle to rendering context
HDC g_hDC=NULL; // Handle to GDI device context
HWND g_hWnd=NULL; // Handle to window
HINSTANCE g_hInstance=NULL; // Handle to application instance
bool g_bKeys[256]; // Array holds keyboard
bool g_bActive=true; // Active flag (def=true)
bool g_bFullscreen=true; // Fullscreen flag (def=true)
const char szClass[]=\"EasyGL\";
const char szTitle[]=\"EasyGL Polygon APP\";
////////////////////////////////////////////////
// Prototypes
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void DoFramework();
void DoKeyboard();
////////////////////////////////////////////////
// Code
GLvoid resizeGL(GLsizei width, GLsizei height)
{
if (!height) return;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLvoid initializeGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
GLvoid renderGL(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f, 0.0f, -1.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();
glTranslatef(3.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
}
GLvoid trashGL(GLvoid)
{
// If we are in fullscreen then we must
// swith back to desktop settings
if (g_bFullscreen)
{
ChangeDisplaySettings(NULL, 0);
ShowCursor(true);
}
// Do we have an active rendering context?
if (g_hRC)
{
// Try to release DC from RC
if (!wglMakeCurrent(NULL, NULL))
MessageBox(g_hWnd, \"Unable to release Device Context from Rendering Context.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
// Try to delete RC
if (!wglDeleteContext(g_hRC))
MessageBox(g_hWnd, \"Unable to delete Rendering Context.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
// Reset RC
g_hRC=NULL;
}
// Do we have an active device context?
if (g_hDC)
{
// Try to release DC
if (!ReleaseDC(g_hWnd, g_hDC))
MessageBox(g_hWnd, \"Unable to release Device Context.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
// Reset DC
g_hDC=NULL;
}
// Do we have an active window handle?
if (g_hWnd)
{
// Try to destroy the window handle
if (!DestroyWindow(g_hWnd))
MessageBox(g_hWnd, \"Unable to destroy Window Handle.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
// Reset the window handle
g_hWnd=NULL;
}
// Are we able to unregister class
if (!UnregisterClass(szClass, g_hInstance))
MessageBox(g_hWnd, \"Unable to Unregister Class.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
// Reset application instance
g_hInstance=NULL;
}
bool createGL(int width, int height, int bits)
{
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bits,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
g_hDC=GetDC(g_hWnd);
if (!g_hDC)
{
MessageBox(g_hWnd, \"Unable to create an OpenGL Device Context.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
return false;
}
GLuint PixelFormat;
PixelFormat=ChoosePixelFormat(g_hDC, &pfd);
if (!PixelFormat)
{
MessageBox(g_hWnd, \"Unable to find a suitable PixelFormat.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
return false;
}
if (!SetPixelFormat(g_hDC, PixelFormat, &pfd))
{
MessageBox(g_hWnd, \"Unable to set the PixelFormat.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
return false;
}
g_hRC=wglCreateContext(g_hDC);
if (!g_hRC)
{
MessageBox(g_hWnd, \"Unable to create an OpenGL Rendering Context.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
return false;
}
if (!wglMakeCurrent(g_hDC, g_hRC))
{
MessageBox(g_hWnd, \"Unable to activate the OpenGL Rendering Context.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
return false;
}
initializeGL();
resizeGL(width, height);
return true;
}
bool newWndClass(void)
{
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndClass.lpfnWndProc = (WNDPROC)WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = g_hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wndClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = NULL;
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = szClass;
if (!RegisterClassEx(&wndClass))
return false;
return true;
}
bool newWindow(const char title[], int width, int height, int bits, bool fullscreen)
{
if (fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(g_hWnd, \"The requested Fullscreen mode IS NOT supported by your Video Card!\\nUse Windowed mode instead? Selecting NO will shutdown the Framework.\", \"Framework Question\", MB_YESNO | MB_ICONQUESTION) == IDYES)
fullscreen=false;
else
return false;
}
}
g_bFullscreen=fullscreen;
DWORD dwExStyle = (fullscreen) ? (WS_EX_APPWINDOW | WS_EX_TOPMOST) : (WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
DWORD dwStyle = (fullscreen) ? (WS_POPUP) : (WS_OVERLAPPEDWINDOW);
RECT WndRect=
{ 0,
0,
width,
height
};
AdjustWindowRectEx(&WndRect, dwStyle, NULL, dwExStyle);
width=WndRect.right-WndRect.left;
height=WndRect.bottom-WndRect.top;
g_hWnd=CreateWindowEx(dwExStyle,
szClass,
title,
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | dwStyle,
0, 0,
width,
height,
NULL,
NULL,
g_hInstance,
NULL);
if (!g_hWnd)
return false;
return true;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
g_hInstance=hInstance;
if (!newWndClass())
{
MessageBox(g_hWnd, \"Unable to Register Framework Class.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
trashGL();
return 0;
}
if (MessageBox(g_hWnd, \"Would you like to run in Fullscreen Mode?\", \"Framework Question\", MB_YESNO | MB_ICONQUESTION) == IDNO)
g_bFullscreen=false;
if (!newWindow(szTitle, 640, 480, 16, g_bFullscreen))
{
MessageBox(g_hWnd, \"Unable to Create a Framework Window.\", \"Framework Error!\", MB_OK | MB_ICONINFORMATION);
trashGL();
return 0;
}
if (!createGL(640, 480, 16))
{
trashGL();
return 0;
}
ShowWindow(g_hWnd, SW_SHOW);
SetForegroundWindow(g_hWnd);
SetFocus(g_hWnd);
// Message loop
MSG msg;
do
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
DoFramework();
} while (1);
trashGL();
return msg.wParam;
}
void DoFramework(void)
{
if (g_bActive)
{
DoKeyboard();
renderGL();
SwapBuffers(g_hDC);
}
}
void DoKeyboard(void)
{
if (g_bKeys[VK_ESCAPE]) PostMessage(g_hWnd, WM_CLOSE, 0, 0);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_ACTIVATE:
{
if (HIWORD(wParam))
g_bActive=false;
else
g_bActive=true;
return 0;
}
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_MONITORPOWER:
case SC_SCREENSAVE:
return 0;
}
break;
}
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
g_bKeys[(int)wParam]=true;
return 0;
}
case WM_KEYUP:
{
g_bKeys[(int)wParam]=false;
return 0;
}
case WM_SIZE:
{
resizeGL(LOWORD(lParam), LOWORD(lParam));
return 0;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
/////////////// SLUT ///////////////
Mange TAK !!!!