Advertisement

Lesson 1 problems

Started by June 16, 2003 08:58 AM
1 comment, last by sSimontis 21 years, 8 months ago
I am having problems with lesson 1 under Dev-C++ 4.9.8.0. Below are the listed errors and the code the errors are in: Line 79 syntax error before '','' token. Line 80 syntax error before '','' token. Line 81 syntax error before '','' token. Line 82 ISO C++ forbids decleration of of ''fulscreen with no type Line 82 conflicting types for ''int fullscreen'' Line 11 Previous decleration asa ''bool fullscreen'' Line 82 ''fullscreenflag'' was not declared in this scope And it continues to go on to some 34 errors. Some of them take place in line 3,000 though! Here is my code:
//Lesson 1 Code

#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 GLResizeScene(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.0f, 0.0f, 0.0f, 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();
return true;
}
GLvoid GLKillWindow(GLvoid)
{
if (fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
if (hRC)
{
if (!wglMakeCurrent(NULL, NULL))
{
MessageBox(NULL,"Release of DC and RC Failed.","SHUTDOWN ERROR!",MB_OK | MB_ICONEXCLAMATION);
}
if (!wglDeleteContext(hRC))
{
MessageBox(NULL,"Release of Rendering Content Failed.","SHUTDOWN ERROR!",MB_OK | MB_ICONEXCLAMATION);
}
hRC=NULL;
}
if (hDC && !ReleaseDC(hWnd,hDC))
{
MessageBox(NULL,"Release Device Content Failed.","SHUTDOWN ERROR!",MB_OK | MB_ICONEXCLAMATION);
hWnd=NULL;
}
if (!UnregisterClass("OpenGL",hInstance))
{
MessageBox(NULL,"Could not Unregister Class.","SHUTDOWN ERROR!",MB_OK | MB_ICONEXCLAMATION);
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.","ERROR!",MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (fullscreen)
{
DEVMODE     dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth=width;
dmScreenSettings.dmpelsheight=height;
dmScreenSettings.dmPerPel=bits;
dmScreenSettings.dmFields=DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFULL)
{
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","Video Card Error!",MB_YESNO | MB_ICONEXCLAMATION)==IDYES);
{
fullscreen=false;
}
else
{
MessageBox(NULL,"Program Will Now Close do to Video Card Errors.","Video card Error!",MB_OK | MB_ICONSTOP);
return false;
}
}
}
if (fullscreen)
{
deExStyle=WS_EX_APPWINDOW;
deStyle=WS_POPUP;
ShowCursor(TRUE);
}
else
{
dwExStyle=WS_EX_STYLE_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
if (!(hWnd=CreateWindowEx(  dwExStyle,
                            "Open GL",
                            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_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();
MessageBox(NULL,"Can''t Create a GL Device Content.","Error!",MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
KillGLWindow();
MessageBox(NULL,"Can''t Find A Suitable Pixel Format.","Error!",MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!PixelFormat(hDC,PixelFormat,&pfd))
{
KillGLWindow();
MessageBox(NULL,"Can''t Set the pixel Format.","Error!",MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!(hRC=wglCreateContext(hDC)))
{
KillGLWindow();
MessageBox(NULL,"Can''t Createb a GL Rendering Context.","Error!",MB_OK | MB_ICONINFORMATION);
return false;
}
if(!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,"Can''t Activate the GL Rendering Context.","Error!",MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,"Can''t Activate the GL Rendering Content","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))
{
activate=true;
}
else
{
activate=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;
}
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(     HISNATNCE   hInstance,
                        HISNATNCE   hPrevInstance,
                        LPSTR       lpCmdLine,
                        int         nCmdShow)
{
MSG msg;
bool done=false;
if(MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?","Start Fullscreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=false;
}
if (!CreateGLWindow("Open GL Window",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);
DispatchMessahe(&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("Open GL Window",640,480,16,fullscreen))
{
return 0;
}
}
}
}
KillGLWidnow();
return (msg.wParam);
}
Thank you. Scott Simontis Engineer in Training Have a nice day!
Scott SimontisMy political blog
For the declaration of the function CreateGLWindow, you end the line with a '';'', however you should be removing this and putting an opening brace''{'' on the next line
Advertisement
Thank you. Now I keep getting parse errors related to ''if'' and ''else'' statements.

Scott Simontis
Engineer in Training
Have a nice day!
Scott SimontisMy political blog

This topic is closed to new replies.

Advertisement