PDA

View Full Version : OpenGL 1.1 & GLUT 3.7: 102 Build Error Tasks Shown (Filtered) on MS VC++ .NET 2002



ScottChang
02-05-2004, 04:49 AM
Hi All,
I tried to the attached OpenGL code to draw a Star-shaped figure on my Microsoft Visual C++ .NET 2002-Windows XP Pro PC. When I did 'Build' in Debug Mode, I got 102 Build error tasks shown (filtered): 1) error C2078: too many initializers, 2) error C2365: 'glBegin' redefinition; previous definition was a 'function'/ 'glVertex3f' redefinition was a
function', 3) error 2501:'glColor3f': missing storage-class or type specifiers, 4) fatal error C1003: error count exceeds 100, stopping compilation. Please help and tell me what it is wrong with my coding in this program and how to correct the program.
Thanks in advance,
Scott Chang
==========================
// ---StarOGLkeys.cpp---
// ---Rotating Star by strucking keys---

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
//#include <gl/glaux.h>
#include <gl/glut.h>
#include <stdlib.h>
// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;

void SetupRC()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
}

// Called to draw scene

void RenderScene(void)
{
// Clear the window
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Save matrix state and do the rotation
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
}

//*******Add Star Data here********
//******Here's Where We Do All The Drawing
// Reset The Current Modelview Matrix
glTranslatef(0.0f,1.0f,0.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_LINE_LOOP); // Drawing a star by using 10 vertices for the outer rims of a star
glVertex3f (0, 0.5, 0); //Specify the next 10 vertices
glVertex3f (-0.2, 0.2, 0); //Specify the next 10 vertices
glVertex3f (-0.5, 0.1, 0);
glVertex3f (-0.2, -0.1, 0);
glVertex3f (-0.3, -0.5, 0);
glVertex3f (0, -0.2, 0);
glVertex3f (0.3, -0.5, 0);
glVertex3f (0.2, -0.1, 0);
glVertex3f (0.5, 0.1, 0);
glVertex3f (0.2, 0.2, 0);
glVertex3f (0, 0.5, 0);
glEnd(); // Finished drawing the star shape
glColor3f (0.0, 1.0, 0.0); //Set the color to green
glBegin(GL_LINES); //Draw 10 lines radiating from (0,0,0) to each vertice
glVertex3f (0, 0.5, 0); //1st vertex to connect the origin to form a line
glVertex3f (0, 0, 0);
glVertex3f (-0.2, 0.2, 0); //2nd vertex
glVertex3f (0, 0, 0);
glVertex3f (-0.5, 0.1, 0);
glVertex3f (0, 0, 0);
glVertex3f (-0.2, -0.1, 0);
glVertex3f (0, 0, 0);
glVertex3f (-0.3, -0.5, 0);
glVertex3f (0, 0, 0);
glVertex3f (0, -0.2, 0);
glVertex3f (0, 0, 0);
glVertex3f (0.3, -0.5, 0);
glVertex3f (0, 0, 0);
glVertex3f (0.2, -0.1, 0);
glVertex3f (0, 0, 0);
glVertex3f (0.5, 0.1, 0);
glVertex3f (0, 0, 0);
glVertex3f (0.2, 0.2, 0);
glVertex3f (0, 0, 0);
glColor3f (0.5, 0.5, 1.0); //Set the color to blue
glVertex3f (0, 0.5, 0);// last vertex
glVertex3f (0, 0, 0);
glEnd(); // Finished drawing the last line

glColor3f (1.0, 0.0, 0.0); //Set the color to red
glBegin(GL_TRIANGLES);
glVertex3f (0, 0, 0);
glVertex3f (0.5, 0.1, 0);
glVertex3f (0.2, 0.2, 0);
glEnd();

//return 0;
}

// Restore transformations
glPopMatrix();

// Flush drawing commands
glutSwapBuffers();

//***Stricking Keys here****
void SpecialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
xRot-= 5.0f;

if(key == GLUT_KEY_DOWN)
xRot += 5.0f;

if(key == GLUT_KEY_LEFT)
yRot -= 5.0f;

if(key == GLUT_KEY_RIGHT)
yRot += 5.0f;

if(key > 356.0f)
xRot = 0.0f;

if(key < -1.0f)
xRot = 355.0f;

if(key > 356.0f)
yRot = 0.0f;

if(key < -1.0f)
yRot = 355.0f;

// Refresh the Window
glutPostRedisplay();
}

void ChangeSize(int w, int h)
{
GLfloat lightPos[] = { -50.f, 50.0f, 100.0f, 1.0f };
GLfloat nRange = 1.9f;

// Prevent a divide by zero
if(h == 0)
h = 1;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

// Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

// Window position (from top corner), and size (width and hieght)
glutInitWindowPosition( 100, 100 );
glutInitWindowSize( 360, 360 );
glutCreateWindow("StarOGLkeys-GLUT Shapes");
glutDisplayFunc(RenderScene);
glutIdleFunc(RenderScence);
glutReshapeFunc(ChangeSize);

SetupRC();
glutMainLoop();
glutKeyboardFub(NormalKeys);
glutSpecialFunc(SpecialKeys);

//return 0;
}

stonemetal
02-05-2004, 03:05 PM
I didn't get to read your code very carefully I am at work but it sounds like you are not including the lib files.