openGL-Fensterklasse zeigt nix
-
Aalso bau grad an einer Klasse, die mir ein openGL-Fenster mit externer Datenhaltung realisieren soll. Das Ganze möchte ich in ein einfaches Modelling-Tool einbauen.
Iiirgendwie wills aber noch nicht so richtig -> mein Fenster bleibt schwarz..hier mal der Code (weil's so viel ist, hab ich nen paar hier nicht relevante sachen rausgenommen..)
#ifndef C3DEDITOR_H_ #define C3DEDITOR_H_ #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <vector> #include <iostream> using namespace std; #define T_TEXTURE 1 #define T_POINT 2 #define T_TRIANGLE 3 #define T_LINE 4 #define DT_TEXTURES 1 #define DT_POINTS 2 #define DT_TRIANGLES 4 #define DT_LINES 8 struct sTexture { char filename[256]; int texture; int texSize; // 2 ^n }; struct sPoint { float position[3]; int texture; int pointS; int pointT; bool active; sPoint() { pointS = 0; pointT = 0; texture = -1; position[0] = 0; position[1] = 0; position[2] = 0; active = false; } }; struct sFace { int type; bool active; sFace () { type = T_TRIANGLE; active = false; } }; struct sLine:sFace { int point[2]; sLine() { type = T_LINE; } }; struct sTriangle:sFace { int point[3]; sTriangle () { type = T_TRIANGLE; } }; struct s3dData { /* typ status rgb */ GLbyte colors[4][2][3]; vector <sFace *> faces; vector <sPoint *> points; vector <sTexture *> textures; vector <sFace *> activeFaces; vector <sPoint *> activePoints; int action; double mousepos[3]; s3dData() { action = 0; memset (&colors,1, sizeof(GLbyte) * 3 * 8); memset (&mousepos, 0, sizeof(double) * 3); } }; class c3deditor { private: HWND hWnd; HWND hParent; HINSTANCE hThisInstance; HDC hDC; HGLRC hRC; RECT dimension; void EnableOpenGL(void); void DisableOpenGL(void); int drawType; float position[3]; float look_at[3]; public: s3dData *myData; c3deditor(s3dData *data, HWND parent, HINSTANCE hThisInstance); virtual ~c3deditor(); static LRESULT CALLBACK handleEvent (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); void draw (void); void move (int x, int y); void size (int w, int h); void setPosition (float x, float y, float z); void setLookat (float x, float y, float z); }; #endif /*C3DEDITOR_H_*/#include "c3deditor.h" c3deditor::c3deditor(s3dData *data, HWND parent, HINSTANCE hThisInstance) { this->myData = data; this->hParent = parent; this->hThisInstance = hThisInstance; this->dimension.left = 0; this->dimension.top = 0; this->dimension.right = 320; this->dimension.bottom = 240; this->drawType = DT_POINTS | DT_LINES | DT_TRIANGLES; WNDCLASS wc; /* register window class */ wc.style = CS_OWNDC; wc.lpfnWndProc = c3deditor::handleEvent; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hThisInstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "GLEditor"; RegisterClass (&wc); /* create main window */ hWnd = CreateWindow ( "GLEditor", "GL View", WS_CHILD | WS_OVERLAPPEDWINDOW | WS_VISIBLE , dimension.left, dimension.top, dimension.right, dimension.bottom, hParent, NULL, hThisInstance, NULL); /* save this */ SetWindowLong (this->hWnd, GWL_USERDATA, (long) this); /* enable OpenGL for the window */ EnableOpenGL (); this->setLookat(0,0,0); this->setPosition (0, 0, -1.0); draw(); } /******************* * Enable OpenGL * *******************/ void c3deditor::EnableOpenGL (void){ PIXELFORMATDESCRIPTOR pfd; int iFormat; /* get the device context (DC) */ hDC = GetDC (hWnd); /* set the pixel format for the DC */ ZeroMemory (&pfd, sizeof (pfd)); pfd.nSize = sizeof (pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat (hDC, &pfd); SetPixelFormat (hDC, iFormat, &pfd); /* create and enable the render context (RC) */ hRC = wglCreateContext( hDC ); wglMakeCurrent( hDC, hRC ); glEnable (GL_DEPTH_TEST); } /****************** * Disable OpenGL * ******************/ void c3deditor::DisableOpenGL (void){ wglMakeCurrent (NULL, NULL); wglDeleteContext (hRC); ReleaseDC (hWnd, hDC); } /****************** * Window Procedure * ******************/ LRESULT CALLBACK c3deditor::handleEvent (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { c3deditor *self = (c3deditor*) GetWindowLong (hWnd, GWL_USERDATA); switch (message) { case WM_CREATE: break; case WM_DESTROY: break; default: return DefWindowProc (hWnd, message, wParam, lParam); } return 0; } /****************** * draw the window * ******************/ void c3deditor::draw (void) { vector<sPoint *>::iterator itp; vector<sFace *>::iterator itf; sPoint *point; sLine *line; sTriangle *triangle; /* set camera perspective */ gluLookAt ( position[0], position[1], position[2], look_at[0], look_at[1], look_at[2], 0, 1, 0); glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); if ((this->drawType & DT_POINTS)!= 0) { glPointSize (3.0); glBegin(GL_POINTS); for ( itp = this->myData->points.begin(); itp != this->myData->points.end(); itp++ ) { cout << "drawing at " << (*itp)->position[0] << ":" << (*itp)->position[1] << ":" << (*itp)->position[2] << ".\n"; glColor3bv(this->myData->colors[T_POINT][(*itp)->active]); glVertex3f((*itp)->position[0], (*itp)->position[1], (*itp)->position[2]); } glEnd(); // draw each point } for ( itf = this->myData->faces.begin(); itf != this->myData->faces.end(); itf++ ) { glColor3bv(this->myData->colors[(*itf)->type][(*itf)->active]); switch ((*itf)->type) { case T_LINE: line = (sLine*) (*itf); glBegin(GL_LINES); glVertex3fv(this->myData->points[line->point[0]]->position); glVertex3fv(this->myData->points[line->point[1]]->position); glEnd(); break; case T_TRIANGLE: triangle = (sTriangle*) (*itf); glBegin(GL_TRIANGLES); /* draw first point */ point = this->myData->points[triangle->point[0]]; glVertex3fv(point->position); if (this->drawType & DT_TEXTURES && point->texture != -1) { glBindTexture ( GL_TEXTURE_2D, this->myData->textures[point->texture]->texture); glTexCoord2f(point->pointS, point->pointT); } /* draw second point */ point = this->myData->points[triangle->point[1]]; glVertex3fv(point->position); if (this->drawType & DT_TEXTURES && point->texture != -1) { glBindTexture ( GL_TEXTURE_2D, this->myData->textures[point->texture]->texture); glTexCoord2f(point->pointS, point->pointT); } /* draw third point */ point = this->myData->points[triangle->point[2]]; glVertex3fv(point->position); if (this->drawType & DT_TEXTURES && point->texture != -1) { glBindTexture ( GL_TEXTURE_2D, this->myData->textures[point->texture]->texture); glTexCoord2f(point->pointS, point->pointT); } glEnd(); break; } } glPopMatrix(); SwapBuffers(hDC); }Punkte hab ich testweise auch mal reingesetzt.
#ifdef TEST sPoint *pt = new sPoint; this->myData.points.push_back (pt); pt = new sPoint; pt->position[1] = 0.5; this->myData.points.push_back (pt); pt = new sPoint; pt->position[1] = 0.5; pt->position[0] = 0.5; this->myData.points.push_back (pt); sTriangle *tr = new sTriangle; tr->point[0] = 0; tr->point[1] = 1; tr->point[2] = 2; this->myData.faces.push_back (tr); #endiföhmm... TEST ist auch definiert.
Kann mir jemand zufällig meinen Fehler nennen? Ich seh nichts mehr..
-
ich vergaß : die Testausgabe in der draw-Methode ( in eine Textdatei umgeleitet ) funktioniert...
-
Hab heut mal noch was anderes probiert und ganz frech den DemoCode vom DEvCpp (das drehende Dreieck) dargestellt und auch das will nicht. Der Fehler ist also nicht in der großen draw-Methode zu suchen.
So langsam keks ich hier aus.
-
Wo setzt du den Viewport?
Hast du die Projektions- und Modelview-Martix richtig gesetzte?
-
hatt ich schon..
Hab mein Problem allerdings gelöst.
Es wurde gezeichnet- aaaber dann schlug die WM_PAINT des Mutterfensters zu..
Hatte WS_CLIPCHILDREN vergessen beim Erstellen des Hauptfensters..