OpenGL-Dev-C++: Fehlermeldung bei Device Context-Bin am verzweifeln!!!



  • Hi Leute,
    erstmal sag ich im Voraus danke an alle die mir Tips und Antworten geben.
    Mein Problem ist, das mir im Device Context jedesmal beim compilen eine Fehlermeldung ausgegeben wird. Jedesmal wenn ich den Code selber schreibe kommt dieser Fehler, allerdings nicht wnen ich ihn aus einem Beispiel kopiert hab.
    Hier die Compiler-Fehlermeldung :

    D:\Dokumente und Einstellungen\Underground\Eigene Dateien\lesson05\lesson5.cpp In function `BOOL CreateGLWindow(char*, int, int, int, bool)': 
    
    282 D:\Dokumente und Einstellungen\Underground\Eigene Dateien\lesson05\lesson5.cpp `pfd' undeclared (first use this function) 
    
      (Each undeclared identifier is reported only once for each function it appears in.) 
    ..........
    

    Hier mein Device Context :

    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();
    return FALSE;
    }
    if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
    {
    KillGLWindow();
    return FALSE;
    }
    if(!SetPixelFormat(hDC,PixelFormat,&pfd))
    {
    KillGLWindow();
    return FALSE;
    }
    if(!(hRC=wglCreateContext(hDC)))
    {
    KillGLWindow();
    return FALSE;
    }
    if(!wglMakeCurrent(hDC,hRC))
    {
    KillGLWindow();
    return FALSE;
    }
    
    ShowWindow(hWnd,SW_SHOW);
    SetFocus(hWnd);
    SetForegroundWindow(hWnd);
    ReSizeGLScene(width,height);
    return TRUE;
    }
    

  • Mod

    welche ist zeile 282 bei dir?



  • Kannste den Code mal bissi formatieren? (so kann das kein Schwein lesen)
    Außerdem kann der Code wie du ihn gepostest hast ja kaum in deinem Programm stehen - du musst also schon noch die relevanten Stellen zeigen.

    Wenn ich die Meldung richtig interpretiere, benutzt du in Zeile 282 den Bezeichner pfd, der an dieser Stelle aber nicht deklariert ist und folglich dem Compiler nicht bekannt ist.



  • Also hier der komplette Code um die Missverständisse aufzudecken :
    P.S: Ich hab alles vor BOOL CreateGLWindow kopiert, weil ab da meine Fehklerquelle begann.

    /*
     *		This Code Was Created By Jeff Molofee 2000
     *		A HUGE Thanks To Fredric Echols For Cleaning Up
     *		And Optimizing The Base Code, Making It More Flexible!
     *		If You've Found This Code Useful, Please Let Me Know.
     *		Visit My Site At nehe.gamedev.net
     */
    
    #include <windows.h>		// Header File For Windows
    #include <gl\gl.h>			// Header File For The OpenGL32 Library
    #include <gl\glu.h>			// Header File For The GLu32 Library
    #include <gl\glaux.h>		// Header File For The Glaux Library
    
    HDC			hDC=NULL;		// Private GDI Device Context
    HGLRC		hRC=NULL;		// Permanent Rendering Context
    HWND		hWnd=NULL;		// Holds Our Window Handle
    HINSTANCE	hInstance;		// Holds The Instance Of The Application
    
    bool	keys[256];			// Array Used For The Keyboard Routine
    bool	active=TRUE;		// Window Active Flag Set To TRUE By Default
    bool	fullscreen=TRUE;	// Fullscreen Flag Set To Fullscreen Mode By Default
    
    GLfloat	rtri;				// Angle For The Triangle ( NEW )
    GLfloat	rquad;				// Angle For The Quad ( NEW )
    
    LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc
    
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)		// Resize And Initialize The GL Window
    {
    	if (height==0)										// Prevent A Divide By Zero By
    	{
    		height=1;										// Making Height Equal One
    	}
    
    	glViewport(0,0,width,height);						// Reset The Current Viewport
    
    	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
    	glLoadIdentity();									// Reset The Projection Matrix
    
    	// Calculate The Aspect Ratio Of The Window
    	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
    
    	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
    	glLoadIdentity();									// Reset The Modelview Matrix
    }
    
    int InitGL(GLvoid)										// All Setup For OpenGL Goes Here
    {
    	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
    	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
    	glClearDepth(1.0f);									// Depth Buffer Setup
    	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
    	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
    	return TRUE;										// Initialization Went OK
    }
    
    int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
    	glLoadIdentity();									// Reset The Current Modelview Matrix
    	glTranslatef(-1.5f,0.0f,-6.0f);						// Move Left 1.5 Units And Into The Screen 6.0
    	glRotatef(rtri,0.0f,1.0f,0.0f);	
        glRotatef(rtri,1.0f,0.0f,0.0f);
        glRotatef(rtri,0.0f,0.0f,1.0f);					// Rotate The Triangle On The Y axis ( NEW )
    	glBegin(GL_TRIANGLES);								// Start Drawing A Triangle
    		glColor3f(1.0f,0.0f,0.0f);						// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Front)
    		glColor3f(0.0f,1.0f,0.0f);						// Green
    		glVertex3f(-1.0f,-1.0f, 1.0f);					// Left Of Triangle (Front)
    		glColor3f(0.0f,0.0f,1.0f);						// Blue
    		glVertex3f( 1.0f,-1.0f, 1.0f);					// Right Of Triangle (Front)
    		glColor3f(1.0f,0.0f,0.0f);						// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Right)
    		glColor3f(0.0f,0.0f,1.0f);						// Blue
    		glVertex3f( 1.0f,-1.0f, 1.0f);					// Left Of Triangle (Right)
    		glColor3f(0.0f,1.0f,0.0f);						// Green
    		glVertex3f( 1.0f,-1.0f, -1.0f);					// Right Of Triangle (Right)
    		glColor3f(1.0f,0.0f,0.0f);						// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Back)
    		glColor3f(0.0f,1.0f,0.0f);						// Green
    		glVertex3f( 1.0f,-1.0f, -1.0f);					// Left Of Triangle (Back)
    		glColor3f(0.0f,0.0f,1.0f);						// Blue
    		glVertex3f(-1.0f,-1.0f, -1.0f);					// Right Of Triangle (Back)
    		glColor3f(1.0f,0.0f,0.0f);						// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);					// Top Of Triangle (Left)
    		glColor3f(0.0f,0.0f,1.0f);						// Blue
    		glVertex3f(-1.0f,-1.0f,-1.0f);					// Left Of Triangle (Left)
    		glColor3f(0.0f,1.0f,0.0f);						// Green
    		glVertex3f(-1.0f,-1.0f, 1.0f);					// Right Of Triangle (Left)
    	glEnd();											// Done Drawing The Pyramid
    
    	glLoadIdentity();									// Reset The Current Modelview Matrix
    	glTranslatef(1.5f,0.0f,-7.0f);						// Move Right 1.5 Units And Into The Screen 7.0
    	glRotatef(rquad,1.0f,1.0f,1.0f);					// Rotate The Quad On The X axis ( NEW )
    	glBegin(GL_QUADS);									// Draw A Quad
    		glColor3f(0.0f,1.0f,0.0f);						// Set The Color To Blue
    		glVertex3f( 1.0f, 1.0f,-1.0f);					// Top Right Of The Quad (Top)
    		glVertex3f(-1.0f, 1.0f,-1.0f);					// Top Left Of The Quad (Top)
    		glVertex3f(-1.0f, 1.0f, 1.0f);					// Bottom Left Of The Quad (Top)
    		glVertex3f( 1.0f, 1.0f, 1.0f);					// Bottom Right Of The Quad (Top)
    		glColor3f(1.0f,0.5f,0.0f);						// Set The Color To Orange
    		glVertex3f( 1.0f,-1.0f, 1.0f);					// Top Right Of The Quad (Bottom)
    		glVertex3f(-1.0f,-1.0f, 1.0f);					// Top Left Of The Quad (Bottom)
    		glVertex3f(-1.0f,-1.0f,-1.0f);					// Bottom Left Of The Quad (Bottom)
    		glVertex3f( 1.0f,-1.0f,-1.0f);					// Bottom Right Of The Quad (Bottom)
    		glColor3f(1.0f,0.0f,0.0f);						// Set The Color To Red
    		glVertex3f( 1.0f, 1.0f, 1.0f);					// Top Right Of The Quad (Front)
    		glVertex3f(-1.0f, 1.0f, 1.0f);					// Top Left Of The Quad (Front)
    		glVertex3f(-1.0f,-1.0f, 1.0f);					// Bottom Left Of The Quad (Front)
    		glVertex3f( 1.0f,-1.0f, 1.0f);					// Bottom Right Of The Quad (Front)
    		glColor3f(1.0f,1.0f,0.0f);						// Set The Color To Yellow
    		glVertex3f( 1.0f,-1.0f,-1.0f);					// Top Right Of The Quad (Back)
    		glVertex3f(-1.0f,-1.0f,-1.0f);					// Top Left Of The Quad (Back)
    		glVertex3f(-1.0f, 1.0f,-1.0f);					// Bottom Left Of The Quad (Back)
    		glVertex3f( 1.0f, 1.0f,-1.0f);					// Bottom Right Of The Quad (Back)
    		glColor3f(0.0f,0.0f,1.0f);						// Set The Color To Blue
    		glVertex3f(-1.0f, 1.0f, 1.0f);					// Top Right Of The Quad (Left)
    		glVertex3f(-1.0f, 1.0f,-1.0f);					// Top Left Of The Quad (Left)
    		glVertex3f(-1.0f,-1.0f,-1.0f);					// Bottom Left Of The Quad (Left)
    		glVertex3f(-1.0f,-1.0f, 1.0f);					// Bottom Right Of The Quad (Left)
    		glColor3f(1.0f,0.0f,1.0f);						// Set The Color To Violet
    		glVertex3f( 1.0f, 1.0f,-1.0f);					// Top Right Of The Quad (Right)
    		glVertex3f( 1.0f, 1.0f, 1.0f);					// Top Left Of The Quad (Right)
    		glVertex3f( 1.0f,-1.0f, 1.0f);					// Bottom Left Of The Quad (Right)
    		glVertex3f( 1.0f,-1.0f,-1.0f);					// Bottom Right Of The Quad (Right)
    	glEnd();											// Done Drawing The Quad
    
    	rtri+=0.2f;											// Increase The Rotation Variable For The Triangle ( NEW )
    	rquad-=0.15f;										// Decrease The Rotation Variable For The Quad ( NEW )
    	return TRUE;										// Keep Going
    }
    
    GLvoid KillGLWindow(GLvoid)								// Properly Kill The Window
    {
    	if (fullscreen)										// Are We In Fullscreen Mode?
    	{
    		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop
    		ShowCursor(TRUE);								// Show Mouse Pointer
    	}
    
    	if (hRC)											// Do We Have A Rendering Context?
    	{
    		if (!wglMakeCurrent(NULL,NULL))					// Are We Able To Release The DC And RC Contexts?
    		{
    			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		}
    
    		if (!wglDeleteContext(hRC))						// Are We Able To Delete The RC?
    		{
    			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		}
    		hRC=NULL;										// Set RC To NULL
    	}
    
    	if (hDC && !ReleaseDC(hWnd,hDC))					// Are We Able To Release The DC
    	{
    		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		hDC=NULL;										// Set DC To NULL
    	}
    
    	if (hWnd && !DestroyWindow(hWnd))					// Are We Able To Destroy The Window?
    	{
    		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		hWnd=NULL;										// Set hWnd To NULL
    	}
    
    	if (!UnregisterClass("OpenGL",hInstance))			// Are We Able To Unregister Class
    	{
    		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		hInstance=NULL;									// Set hInstance To NULL
    	}
    }
    
    /*	This Code Creates Our OpenGL Window.  Parameters Are:					*
     *	title			- Title To Appear At The Top Of The Window				*
     *	width			- Width Of The GL Window Or Fullscreen Mode				*
     *	height			- Height Of The GL Window Or Fullscreen Mode			*
     *	bits			- Number Of Bits To Use For Color (8/16/24/32)			*
     *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)	*/
    
    BOOL CreateGLWindow(char *Titel,int width,int height,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)height;
    
    fullscreenflag=fullscreen;
    
    hInstance = GetModuleHandle(NULL);
    wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc = (WNDPROC) WndProc;
    wc.lpszMenuName=NULL;
    wc.lpszClassName="OpenGL";
    wc.cbClsExtra=0;
    wc.cbWndExtra=0;
    wc.hbrBackground=NULL;
    wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    
    if(!RegisterClass(&wc))
    {
    MessageBox(NULL,"Die Fensterregistrierklasse konnte nicht inialisiert werden  !"," Fehler",MB_OK);
    return FALSE;
    }
    
    if(fullscreen)
    {
    DEVMODE dmScreenSettings;
    dmScreenSettings.dmSize=sizeof(dmScreenSettings);
    dmScreenSettings.dmPelsWidth=width;
    dmScreenSettings.dmPelsHeight=height;
    dmScreenSettings.dmBitsPerPel=bits;
    dmScreenSettings.dmFields=DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    }
    
    if(fullscreen)
    {
    dwExStyle=WS_EX_APPWINDOW;
    dwStyle=WS_POPUP;
    }
    
    else
    {
    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    dwStyle=WS_OVERLAPPEDWINDOW;
    ShowCursor(FALSE);
    }
    
    AdjustWindowRectEx(&WindowRect,dwStyle,FALSE,dwExStyle);
    
    if(!(hWnd=CreateWindowEx(
    dwExStyle,
    "OpenGL",
    Titel,
    WS_CLIPSIBLINGS |
    WS_CLIPCHILDREN |
    dwStyle,
    0,0,
    WindowRect.right-WindowRect.left,
    WindowRect.bottom-WindowRect.top,
    NULL,
    NULL,
    hInstance,
    NULL)))
    
    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();
    
    return FALSE;
    }
    
    if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
    {
    KillGLWindow();
    return FALSE;
    }
    
    if(!SetPixelFormat(hDC,PixelFormat,&pfd))
    {
    KillGLWindow();
    return FALSE;
    }
    
    if(!(hRC=wglCreateContext(hDC)))
    {
    KillGLWindow();
    return FALSE;
    }
    
    if(!wglMakeCurrent(hDC,hRC))
    {
    KillGLWindow();
    return FALSE;
    }
    
    ShowWindow(hWnd,SW_SHOW);
    SetFocus(hWnd);
    SetForegroundWindow(hWnd);
    ReSizeGLScene(width,height);
    return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    
    switch(message)
    {
    
    case WM_CLOSE:
    {
    PostQuitMessage(0);
    return 0;
    }
    
    case WM_ACTIVATE:
    {
    if(!HIWORD(wParam))
    {
    active=TRUE;
    }
    else
    {
    active=FALSE;
    }
    return 0;
    }
    
    case WM_SIZE:
    {
    return DefWindowProc(LOWORD(lParam),HIWORD(lParam));
    }
    return DefWindowproc(hWnd,message,wParam,lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
    
    {
    MSG msg;
    BOOL done=FALSE;
    
    if(MessageBox(NULL,"Soll im Vollbild-Modus gestartet werden ?","Steve Wegener's 3D-Test",MB_YESNO)==IDES)
    {
    fullscreen=TRUE;
    }
    else
    {
    fullscreen=FALSE;
    }
    
    if(!CreateGLWindow("Steve Wegener's 3D-Test",1024,768,32,fullscreen))
    {
    return 0;
    }
    
    if(MessageBox(NULL,"Soll der Mauszeiger angezeigt werden ?","Steve Wegener's 3D-Test",MB_YESNO)==IDYES)
    {
    ShowCursor(TRUE);
    }
    else
    {
    ShowCursor(FALSE);
    }
    
    while(!done)
    {
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
    if(msg.message==WM_QUIT)
    {
    done=TRUE;
    }
    else
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    else
    {
    if(active)
    {
    if(keys[VK_ESCAPE])
    {
    done=TRUE;
    }
    else
    {
    DrawGLScene();
    SwapBuffers(hDC);
    }
    }
    
     if(!CreateGLWindow("Steve Wegener's 3D-Test",1024,768,16,fullscreen))
    {
    return 0;
    }
    }
    }
    
    KillGLWindow();
    return (msg.wParam);
    }
    

  • Mod

    pivke schrieb:

    if(!(hWnd=CreateWindowEx(...)))
      static PIXELFORMATDESCRIPTOR pfd=
      {
       ...
      };
    

    eine bedingte declaration?



  • Ich versteh nicht ganz 🙄
    Müsste doch eigentlich so stimmen !?



  • Benutze doch mal bitte die cpp Tags 🙄

    Du weißt schon, dass Variablen nur in ihrem Block (der bei deinem if sehr kurz ist) gelten?



  • Aber hier funktioniert's doch auch so :
    http://www.joachimrohde.com/cms/xoops/modules/articles/article.php?id=5
    Aber ich schau nochmal drüber.


  • Mod

    pivke schrieb:

    Aber hier funktioniert's doch auch so :
    http://www.joachimrohde.com/cms/xoops/modules/articles/article.php?id=5
    Aber ich schau nochmal drüber.

    da steht was anderes. bitte schau doch erst, bevor du hier postest, du ersparst dir einiges an zeit.



  • Also entweder bin ich zu doof oder zu müde um das Rätsel zu lösen 😃



  • Ich würde sagen zu unerfahren. Der Code auf der verlinkten Seite ist eindeutig anders.



  • Mag ja sein, aber wo genau befindet sich mein Fehler?


Log in to reply