Advertisement

very new to opengl and vc++

Started by February 14, 2002 08:09 PM
15 comments, last by phillysnotcool 23 years ago
hey i''m very new to opengl and not that experienced with visual c++. I have been havin trouble getting the very first NeHe tutorial to compile. The error I get is as follows: Deleting intermediate files and output files for project ''firstgl - Win32 Debug''. --------------------Configuration: firstgl - Win32 Debug-------------------- Compiling... firstgl.c c:\devel\firstgl\firstgl.c(186) : error C2143: syntax error : missing '';'' before ''type'' c:\devel\firstgl\firstgl.c(215) : error C2065: ''pfd'' : undeclared identifier c:\devel\firstgl\firstgl.c(215) : warning C4133: ''function'' : incompatible types - from ''int *'' to ''const struct tagPIXELFORMATDESCRIPTOR *'' c:\devel\firstgl\firstgl.c(222) : warning C4133: ''function'' : incompatible types - from ''int *'' to ''const struct tagPIXELFORMATDESCRIPTOR *'' c:\devel\firstgl\firstgl.c(258) : error C2143: syntax error : missing ''{'' before ''__stdcall'' c:\devel\firstgl\firstgl.c(259) : warning C4142: benign redefinition of type Error executing cl.exe. firstgl.exe - 3 error(s), 3 warning(s) line 186 is where the pixel format descriptor is defined. Can anyone please help me with this? thanks a lot jake
post some code ... but only from where the errors occur!

BTW - most of the errors are only caused by the first error!

(double click on the first error - it will take you to the problem line. Copy and paste that here, including a few lines above it.)
Advertisement
judging by the first error it looks like you maybe forgot to include the openGL header files?
hmmm.... id say that there is a '';'' missing somwhare cause the error is a ''syntax'' error !
you forgot to end the line above/before "type" with a semicolon( ; ), im sure thats what the first one means

,Matt

-= kill one your a murderer, kill thousands your a conquerer =-

Edited by - samosa on February 14, 2002 9:32:58 PM
-= kill one you're a murderer, kill thousands you're a conquerer =-
sorry bout no code i meant to put it in. Line 186 would be the line containing "static PIXELFORMATDESCRIPTOR pfd =". Thanks again
-- here''s the whole file:

#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 = TRUE;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

GLvoid ReSizeGLScene (GLsizei width, GLsizei height)
{
if(height==0)
height = 1;

glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL (GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.5f,0.0f,0.2f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
return TRUE;
}

int DrawGLScene (GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

// Move left and in
glTranslatef(-1.5f,0.0f,-6.0f);

// Draw a triangle
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f,0.0f);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();

// Move to the right side of the screen
glTranslatef(3.0f,0.0f,0.0f);

// Draw a quad
glBegin(GL_QUADS);
glVertex3f(-1.0f,1.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,-1.f,0.0f);
glVertex3f(-1.0f,-1.0f,0.0f);
glEnd();

return TRUE;
}

GLvoid KillGLWindow (GLvoid)
{
if(fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}

// Delete Render Context
if(hRC)
{
if(!wglMakeCurrent(NULL,NULL))
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

if(!wglDeleteContext(hRC))
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

hRC = NULL;
}

// Delete Device Context
if(hDC && !ReleaseDC(hWnd,hDC))
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC = NULL;
}

// Destroy Window
if(hWnd && !DestroyWindow(hWnd))
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd = NULL;
}

// Unregister Window Class
if(!UnregisterClass("OpenGL",hInstance))
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance = NULL;
}
}

BOOL CreateGLWindow (char* title, 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;

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 the window class [OpenGL]","ERROR",MB_OK|MB_ICONEXCLAMATION);
}

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,"The requested fullscreen mode is not supported by\nyour video card. Use Windowed Mode instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
{
fullscreen = FALSE;
}
else
{
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE;
}
}
}

// Gotta check again cuz we might be in a window now
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,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

static PIXELFORMATDESCRIPTOR pfd =
}
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLE_BUFFER,
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,"Can''t create a GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if(!(PixelFormat = ChoosePixelFormat(hDC,&pfd)))
{
KillGLWindow();
MessageBox(NULL,"Can''t find a suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if(!(SetPixelFormat(hDC,PixelFormat,&pfd)))
{
KillGLWindow();
MessageBox(NULL,"Can''t set PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if(!(hRC=wglCreateContext(hDC)))
{
KillGLWindow();
MessageBox(NULL,"Can''t create a GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

if(!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,"Can''t activate the GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
ReSizeGLScene(width,height);

if(!InitGL())
{
KillGLWindow();
MessageBox(NULL,"Initialization failed.","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))
active = TRUE;
else
active = FALSE;

return 0;
}
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
keys[wParam] = TRUE;
return 0;
}
case WM_KEYUP:
{
keys[wParam] = FALSE;
return 0;
}
case WM_SIZE:
{
ReSizeGLScene (LOWORD(lParam),HIWORD(lParam));
return 0;
}
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
BOOL done = FALSE;

if(MessageBox(NULL,"Would you like to run in fullscreen mode?","Fullscreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen = FALSE;
}

if(!CreateGLWindow("NeHe''s Polygon Tutorial",640,480,16,fullscreen))
{
return 0;
}

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(keys[VK_F1])
{
keys[VK_F1] = FALSE;
KillGLWindow();
fullscreen = !fullscreen;

if(!CreateGLWindow("NeHe''s Polygon Tutorial",640,480,16,fullscreen))
return 0;
}
}
}

KillGLWindow();
return (msg.wParam);
}
Advertisement
well right after that 186 line, you''ve got a bracket facing the wrong way.
i saw the bracket right after i posted... but i changed it and still get the same error
Well, I don''t know what you did wrong, but after reversing the bracket I got one error in relation to PFD_DOUBLEBUFFER. You added an underscore. I then dealt with the resulting warning by fixing your WndProc to always return some sort of value. You can get the code here. It will disappear in a matter of days

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

As a side note, in order to keep the browser from turning my angle brackets into HTML tags, I replaced them with the appropriate character codes. I''m not sure, but this may affect the look and operation of the code, so be on the lookout for something like

#include lt;windows.hgt;

It''s not a bug. Just change that into

#include <windows.h>

And that''s that.

Hope this helps,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement