013
26.11.2004, 16:07 Uhr
CaesarCortezz
minderer Student
|
C++: |
#include <windows.h> #include <gl\gl.h> #include <gl\glu.h> // #include <gl\glaux.h>
HGLRC hRC=NULL; HDC hDC=NULL; HWND hWnd=NULL; HINSTANCE hInstance;
bool keys[256]; bool active=true; bool fullscreen=false;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { height=1; }
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (GLFloat)width/(GLfloat)height0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity();
int InitGL(GLvoid) { glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return true; }
int glDrawScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); return true; }
GLvoid KillGLWindow(GLvoid) { if (fullscreen) { ChangeDisplaySettings(NULL, 0); ShowCursor=true; } if(hRC) { if(!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL, "Zurückkehren auf den Desktop fehlgeschlagen", "Shutdown Error", MB_OK | MB_ICONINFORMATION); } hRC=NULL; } if (!wglDeleteContext(hRC)) { MessageBox(NULL, "Release device context failed", "Shutdown error", MB_OK | MB_ICONINFORMATION); hDC=NULL; } if (hWnd && !DestroyWindow(hWnd)) { MessageBox(NULL, "Could not release hWnd", "Shutdown error", MB_OK | MB_ICONINFORMATION); hInstance=NULL; } }
bool CreateGLWindow(char* title, int width, int heigth, int bits, bool fullscreenflag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)heigth; fullscreen=fullscreenflag;
hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground= NULL; wc.lpszMenuName = NULL; wc.lpszClassName= "OpenGL";
if (!RegisterClass(&wc)) { MessageBox(NULL, "failed to register wc", "Shutdown Error", MB_OK | MB_ICONEXCLAMATION); return false; } 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(NULL, "ERROR, wollen sie ein Fenster?", "Jay-GL", MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=false; } else { MessageBox(NULL, "Program is shuting down", "ERROR", MB_OK|MB_ICONSTOP); return false; } } } if (fullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; ShowCursor = false; } else { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);
if (!(hWnd=CreateWindowEx( dwExStyle, "OpenGL", title, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL))) { KillGLWindow(); MessageBox(NULL, "Fenster kann net erstellt werden", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } 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 };
if(!(hDC=GetDC(hWnd)) { KillGLWindow(); MessageBox(NULL, "Device Context fucked up", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) { KillGLWindow(); MessageBox(NULL, "Pixel Format fucked up", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } if (!SetPixelFormat(hDC,PixelFormat, &pfd)) { KillGLWindow(); MessageBox(NULL, "Pixel Format set fucked up", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } if (!(hRC=wglCreateContext(hDC))) { KillGLWindow(); MessageBox(NULL, "Rendering Context fucked up", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } if (!wglMakeCurrent(hDC, hRC)) { KillGLWindow(); MessageBox(NULL, "Rendering Context fucked up", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); ReSizeGLScene(width, height);
if (!InitGL()) { KillGLWindow(); MessageBox(NULL, "Initialisation fucked up", "ERROR", MB_OK|MB_ICONEXCLAMATION); return false; } return true; }
LRESULT CALLBACK WndProc( HWND hWnd; UINT uMsg; WPARAM wParam; LPARAM lParam) { switch(uMsg) { case WM_ACTIVATE: { if(!HIWORD(wParam)) { activate=true; } else { activate=false; } return 0; } case WM_SYSCOMMAND: { switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; }
|
errors:
Zitat: |
21 Dtools\C++Dev5\Projekte\main.cpp `width' was not declared in this scope 21 Dtools\C++Dev5\Projekte\main.cpp `height' was not declared in this scope 21 Dtools\C++Dev5\Projekte\main.cpp ISO C++ forbids declaration of `glViewport' with no type
|
und so geht das ne weile... -- Thus spake the master programmer:
``When the program is being tested, it is too late to make design changes.'' |