Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Jul 18, 2025 11:19

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Autor Nachricht
BeitragVerfasst: Do Mär 31, 2005 01:50 
Offline
DGL Member
Benutzeravatar

Registriert: Do Feb 24, 2005 22:44
Beiträge: 29
Hallöchen,

ich hab eine recht einfache Frage eigentlich. Ist ein Child-Fenster auch OpenGL-Fähig? Also ich erstelle 2 Fenster, seperat, keine Childs oder Parents und jeder seine eigene Callback-Prozedur. Eines der Fenster wird OGL-Fähig gemacht, funktioniert auch soweit. Wenn ich dieses eine Fenster nun aber als Childfenster des zweiten angeben will, wird es plötzlich nicht mehr angezeigt. Allein, als Childfenster, ohne die Bereitstellung für OGL funktioniert es aber.

Das Programm als Binary: http://derfeind2k.de/daten/ogl_child.rar (für diejenigen die nicht die Möglichkeit haben, den Sourcecode zu kompilieren)

Dies hier ist der komplette Code: (Benötigt werden folgende Libs: Glu, OpenGL, Win32)
Code:
  1. #include <windows.h>
  2. #include <iostream.h>
  3. #include <GL\gl.h>
  4. #include <GL\glu.h>
  5.  
  6. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  7. LRESULT CALLBACK WndProc_child(HWND, UINT, WPARAM, LPARAM);
  8.  
  9. HINSTANCE hinstance;
  10. HWND hwnd_maparea;
  11. HWND hwnd;              //Handle zum Fenster
  12.    
  13. HGLRC hRC = NULL;
  14. HDC hDC = NULL;
  15.  
  16. bool InitGL(void)
  17. {
  18.     glEnable(GL_TEXTURE_2D);
  19.     glShadeModel(GL_SMOOTH);
  20.  
  21.     glClearColor((float) ((162.0f * 100.0f / 255.0f) / 100.0f), (55.0f * 100.0f / 255.0f) / 100.0f, (55.0f * 100.0f / 255.0f) / 100.0f, 0.0f);
  22.     glClearDepth(1.0f);
  23.     glEnable(GL_DEPTH_TEST);
  24.     glDepthFunc(GL_LEQUAL);
  25.     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  26.     glColor4f(1.0f,1.0f,1.0f,0.5f);         // Full Brightness, 50% Alpha ( NEW )
  27.    
  28.     return TRUE;
  29. }
  30.  
  31.  
  32. bool CreateGlWindow(void)
  33. {
  34.     DWORD dwExStyle;
  35.     DWORD dwStyle;
  36.     RECT WindowRect;
  37.     WindowRect.left = (long) 0;
  38.     WindowRect.right = (long) 640;
  39.     WindowRect.top = (long) 0;
  40.     WindowRect.bottom = (long) 480;
  41.     unsigned int PixelFormat;
  42.  
  43.    
  44.     dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window Extended Style
  45.     dwStyle=WS_OVERLAPPEDWINDOW;                    // Windows Style
  46.  
  47.     AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust Window To True Requested Size
  48.  
  49.     hwnd_maparea = CreateWindow("maparea",
  50.                                 "maparea",
  51.                                 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
  52.                                 100, 30, 640, 480,
  53.                                 NULL,
  54.                                 NULL,
  55.                                 hinstance,
  56.                                 NULL);
  57.  
  58.  
  59.     static  PIXELFORMATDESCRIPTOR pfd=                  // pfd Tells Windows How We Want Things To Be
  60.     {
  61.         sizeof(PIXELFORMATDESCRIPTOR),                  // Size Of This Pixel Format Descriptor
  62.         1,                                      // Version Number
  63.         PFD_DRAW_TO_WINDOW |                    // Format Must Support Window
  64.         PFD_SUPPORT_OPENGL |                    // Format Must Support OpenGL
  65.         PFD_DOUBLEBUFFER,                       // Must Support Double Buffering
  66.         PFD_TYPE_RGBA,                          // Request An RGBA Format
  67.         32,                                     // Select Our Color Depth
  68.         0, 0, 0, 0, 0, 0,                       // Color Bits Ignored
  69.         0,                                      // No Alpha Buffer
  70.         0,                                      // Shift Bit Ignored
  71.         0,                                      // No Accumulation Buffer
  72.         0, 0, 0, 0,                             // Accumulation Bits Ignored
  73.         16,                                     // 16Bit Z-Buffer (Depth Buffer)
  74.         0,                                      // No Stencil Buffer
  75.         0,                                      // No Auxiliary Buffer
  76.         PFD_MAIN_PLANE,                         // Main Drawing Layer
  77.         0,                                      // Reserved
  78.         0, 0, 0                                // Layer Masks Ignored
  79.     };
  80.    
  81.     if (!(hDC=GetDC(hwnd_maparea)))                         // Did We Get A Device Context?
  82.     {
  83.         MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  84.         return FALSE;                           // Return FALSE
  85.     }
  86.    
  87.     if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))             // Did Windows Find A Matching Pixel Format?
  88.     {
  89.         MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  90.         return FALSE;                           // Return FALSE
  91.     }
  92.  
  93.     if(!SetPixelFormat(hDC,PixelFormat,&pfd))               // Are We Able To Set The Pixel Format?
  94.     {
  95.         MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  96.         return FALSE;                           // Return FALSE
  97.     }     
  98.  
  99.     if (!(hRC=wglCreateContext(hDC)))                   // Are We Able To Get A Rendering Context?
  100.     {
  101.         MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  102.         return FALSE;                           // Return FALSE
  103.     }
  104.    
  105.     if(!wglMakeCurrent(hDC,hRC))                        // Try To Activate The Rendering Context
  106.     {
  107.         MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  108.         return FALSE;                           // Return FALSE
  109.     }
  110.    
  111.    
  112.     ShowWindow(hwnd_maparea,SW_SHOW);                       // Show The Window
  113.     SetForegroundWindow(hwnd_maparea);                      // Slightly Higher Priority
  114.     SetFocus(hwnd_maparea);                             // Sets Keyboard Focus To The Window
  115.  
  116.     InitGL();
  117. }
  118.  
  119.  
  120. int DrawGL(void)
  121. {
  122.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
  123.     glLoadIdentity();
  124.    
  125.     glColor4f(1.0, 0.5, 0.0, 0.5);
  126.    
  127.     glBegin(GL_TRIANGLES);
  128.        glVertex3f(0, 0, 0);
  129.        glVertex3f(0, 1, 0);
  130.        glVertex3f(1, 0, 0);
  131.     glEnd();
  132. }
  133.  
  134.  
  135. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  136.                    PSTR szCmdLine, int showpref)
  137. {
  138.     static char AppName[] = "WinTextedit 1.0";
  139.     MSG msg;
  140.     WNDCLASS wndclass;
  141.  
  142.     wndclass.style = CS_HREDRAW | CS_VREDRAW;
  143.     wndclass.lpfnWndProc = WndProc;
  144.     wndclass.cbClsExtra = 0;
  145.     wndclass.cbWndExtra = 0;
  146.     wndclass.hInstance = hinstance;
  147.     wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  148.     wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  149.     wndclass.hbrBackground = (HBRUSH) COLOR_MENU + 3;
  150.     wndclass.lpszMenuName = NULL;
  151.     wndclass.lpszClassName = AppName;
  152.  
  153.    
  154.     if (RegisterClass(&wndclass) == false)
  155.     {
  156.         MessageBox(NULL, "Es ist ein Fehler aufgetreten. ", "Error! ", MB_ICONERROR);
  157.         return 0;
  158.     }
  159.  
  160.     wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  161.     wndclass.hbrBackground = NULL;
  162.     wndclass.lpfnWndProc = WndProc_child;
  163.     wndclass.lpszClassName = "maparea";
  164.  
  165.     if (RegisterClass(&wndclass) == false)
  166.     {
  167.         MessageBox(NULL, "Es ist ein Fehler aufgetreten. ", "Error! ", MB_ICONERROR);
  168.         return 0;
  169.     }
  170.  
  171.     hwnd = CreateWindow (AppName,
  172.                          TEXT("WinProgramm 1.0"),
  173.                          WS_OVERLAPPEDWINDOW,
  174.                          100,
  175.                          100,
  176.                          800,
  177.                          800,
  178.                          NULL,
  179.                          NULL,
  180.                          hInstance,
  181.                          NULL);
  182.  
  183.     ShowWindow(hwnd, SW_SHOWNORMAL);
  184.     UpdateWindow(hwnd);
  185.    
  186.  
  187.     bool done = FALSE;
  188.  
  189.     while(!done)                                // Loop That Runs Until done=TRUE
  190.     {
  191.         if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))           // Is There A Message Waiting?
  192.         {
  193.             if (msg.message==WM_QUIT)               // Have We Received A Quit Message?
  194.             {
  195.                 done=TRUE;                  // If So done=TRUE
  196.             }
  197.             else                            // If Not, Deal With Window Messages
  198.             {
  199.                 TranslateMessage(&msg);             // Translate The Message
  200.                 DispatchMessage(&msg);              // Dispatch The Message
  201.             }
  202.         }
  203.         else                                // If There Are No Messages
  204.         {
  205.             DrawGL();
  206.             SwapBuffers(hDC);
  207.         }
  208.     }
  209.     return (msg.wParam);                            // Exit The Program    
  210. }
  211.  
  212. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  213. {
  214.     switch(message)
  215.     {
  216.  
  217.     case WM_CREATE:
  218.         CreateGlWindow();
  219.         return 0;
  220.                                    
  221.  
  222.     case WM_DESTROY:
  223.         PostQuitMessage(0);    
  224.         return 0;
  225.     }
  226.     return DefWindowProc(hwnd, message, wParam, lParam);
  227. }
  228.  
  229. LRESULT CALLBACK WndProc_child(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  230. {
  231.  
  232.     switch(message)
  233.     {
  234.     case WM_DESTROY:
  235.         PostQuitMessage(0);    
  236.         return 0;
  237.     }
  238.  
  239.     return DefWindowProc(hwnd, message, wParam, lParam);
  240. }


Fügt man nun in der Zeile 51 noch die WS_CHILD Konstante hinzu und setzt als Parent Fenster "hwnd" in der Zeile 53, dann wird kein zweites Fenster mehr erstellt. Weder als Childfenster noch als eigenständiges.

Vielleicht findet ja jemand hier den Fehler. Oder ist ein Childfenster allgemein nicht OGL fähig? Oder gibt es irgendwo Beispiele oder Tutorials für Childfenster die einen OGL-Rendercontext haben?

mfg.

Sunny


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 19 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.007s | 14 Queries | GZIP : On ]