Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
class COpenGL { public: COpenGL(void); ~COpenGL(void); unsigned char key_pressed (); void opengl_setup (); bool opengl_createWindow (HINSTANCE hInst, int iCmdShow, int iWidth, int iHeight); void opengl_reset (); HDC getHDC (); inline void Print () { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0f, 1.0f, 1.0f); glBegin (GL_TRIANGLES); glVertex3f ( 0.0f, 1.0f, -10.0f); glVertex3f (-1.0f, 0.0f, -10.0f); glVertex3f ( 1.0f, 0.0f, -10.0f); glEnd (); } private: HWND hWnd; WNDCLASSEX WndClassEx; MSG msg; HDC* hDC; HGLRC hGLRC; PIXELFORMATDESCRIPTOR pfd; int iFormat; int iWidth; int iHeight; char szWindowTitel [30]; char szClassName [30]; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
COpenGL::COpenGL(void) { strcpy_s ( szClassName, "MyWndclass"); strcpy_s ( szWindowTitel, "My Window"); hDC = new HDC (); } COpenGL::~COpenGL(void) { } LRESULT CALLBACK WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { PostQuitMessage (0); break; } default: return DefWindowProc (hWnd, msg, wParam, lParam); } return 0; } unsigned char COpenGL::key_pressed () { if (PeekMessage ( &msg, hWnd, NULL, NULL, PM_REMOVE)) { if (msg.message==WM_QUIT ||msg.message==WM_KEYDOWN) // Have We Received A Quit Message? { return true; // If So done=TRUE } TranslateMessage (&msg); DispatchMessage (&msg); } return 0; } void COpenGL::opengl_setup () { memset (&pfd, NULL, sizeof(pfd)); pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 32; pfd.cAlphaBits = 8; *hDC = GetDC (hWnd); iFormat = ChoosePixelFormat (*hDC, &pfd); SetPixelFormat (*hDC, iFormat, &pfd); hGLRC = wglCreateContext (*hDC); wglMakeCurrent (*hDC, hGLRC); } bool COpenGL::opengl_createWindow (HINSTANCE hInst, int iCmdShow, int iWidth, int iHeight) { this->iWidth = iWidth; this->iHeight = iHeight; WndClassEx.cbSize = sizeof (WNDCLASSEX); WndClassEx.style = CS_OWNDC | CS_VREDRAW; WndClassEx.cbClsExtra = NULL; WndClassEx.cbWndExtra = NULL; WndClassEx.hInstance = hInst; WndClassEx.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); WndClassEx.hIcon = LoadIcon (NULL, IDI_APPLICATION); WndClassEx.hIconSm = NULL; WndClassEx.hCursor = LoadCursor (NULL, IDC_ARROW); WndClassEx.lpfnWndProc = (WNDPROC) WndProc; WndClassEx.lpszMenuName = NULL; WndClassEx.lpszClassName = szClassName; if (!RegisterClassEx ( &WndClassEx) ) { MessageBox (NULL, "Fail to register WndClassEx", "Erorr", MB_OK | MB_ICONERROR); } hWnd = CreateWindow (szClassName, szWindowTitel, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT , CW_USEDEFAULT, iWidth, iHeight, NULL, NULL, hInst, NULL); if (!hWnd) { MessageBox ( NULL, "Fail to crate a windo", "Erorr", MB_OK | MB_ICONERROR); return false; } ShowWindow (hWnd, iCmdShow); UpdateWindow (hWnd); return true; } void COpenGL::opengl_reset () { if (iWidth == 0) { iWidth = 1; } if (iHeight == 0) { iHeight = 1; } glViewport (0, 0, this->iWidth, this->iHeight); glMatrixMode ( GL_PROJECTION); glLoadIdentity (); gluPerspective (45.0f, this->iWidth/this->iHeight, 1.0f, 100.f); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); } HDC COpenGL::getHDC () { return *hDC; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR IpCmdLine, int iCmdShow) { COpenGL OpenGl; CGame Game; if (!OpenGl.opengl_createWindow (hInst, iCmdShow, 1280, 720)) { return false; } OpenGl.opengl_setup (); OpenGl.opengl_reset (); while (true) { if (OpenGl.key_pressed ()) { break; } else { Game.Print (); if (!OpenGl.getHDC ()) { return false; } SwapBuffers (OpenGl.getHDC ()); } } return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
void CGame::Print () { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f (1.0f, 1.0f, 1.0f); glBegin (GL_TRIANGLES); glVertex3f ( 0.0f, 1.0f, -10.0f); glVertex3f (-1.0f, 0.0f, -10.0f); glVertex3f ( 1.0f, 0.0f, -10.0f); glEnd (); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
PIXELFORMATDESCRIPTOR FormatDesc = { sizeof(PIXELFORMATDESCRIPTOR), // Structure size 1, // Version number PFD_DRAW_TO_WINDOW | // Format must support window PFD_SUPPORT_OPENGL | // Format must support OpenGL PFD_DOUBLEBUFFER, // Must support double buffering PFD_TYPE_RGBA, // Request an RGBA format 32, // Select our color depth 0, 0, 0, 0, 0, 0, // Color bits ignored 0, // No alpha buffer 0, // Shift bit ignored 0, // No accumulation buffer 0, 0, 0, 0, // Accumulation bits ignored 24, // Z-Buffer bits (Depth Buffer) 1, // Stencil buffer 0, // No auxiliary buffer PFD_MAIN_PLANE, // Main drawing layer 0, // Reserved 0, 0, 0 // Layer masks ignored }; |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Volker_Neff« (21.05.2013, 17:10)
C-/C++-Quelltext |
|
1 |
hrc = wglCreateContextAttribsARB(hdc, NULL, attributes);
|
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
HGLRC tempOpenGLContext = wglCreateContext(hdc); // Create an OpenGL 2.1 context for our device context wglMakeCurrent(hdc, tempOpenGLContext); // Make the OpenGL 2.1 context current and active GLenum error = glewInit(); // Enable GLEW if (error != GLEW_OK) // If GLEW fails { return false; } int attributes[] = { 0x2091, 3, // Set the MAJOR version of OpenGL to 3 0x2092, 2, // Set the MINOR version of OpenGL to 2 0x2094, 0x0002, // Set our OpenGL context to be forward compatible 0 }; if (glewIsSupported("WGL_ARB_create_context") == 1) // If the OpenGL 3.x context creation extension is available { hrc = wglCreateContextAttribsARB(hdc, NULL, attributes); // Create and OpenGL 3.x context based on the given attributes wglMakeCurrent(NULL, NULL); // Remove the temporary context from being active wglDeleteContext(tempOpenGLContext); // Delete the temporary OpenGL 2.1 context wglMakeCurrent(hdc, hrc); // Make our OpenGL 3.0 context current } else { hrc = tempOpenGLContext; // If we didn't have support for OpenGL 3.x and up, use the OpenGL 2.1 context } |
"Der Prozedureinsprungspunkt _glewisSupported@4 wurde in der DLL glew32.dll nicht gefunden" Was heist das den jetzt schon wieder? Google kann mir auch nicht helfen
Wozu verwendest du überhaupt GLEW, wenn du deinen GL Kontext und alles selbst erstellen willst?
Kann sein, dass sich das beißt.
"wglCreateContextAttribsARB" brauchst du glaube ich auch nur wenn du Anti-Aliasing haben willst. Ob man das auch zwingend für GL 3.x "Core Profile" braucht, weiß ich nicht.
Werbeanzeige