PDA

View Full Version : OpenGL 1.1- GLUT 3.7 Programming on VC++ .NET 2002: error C2065-undeclared identifier



ScottChang
02-06-2004, 05:54 AM
Hi All,
I tried to use 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 an error C2065: 'RenderScence': undeclared identifier. Please help and tell me (1) what it is wrong with my coding in this program and how to correct the problem, and (2) whether the functions/commands of the OpenGL v1.1 (existing in Microsoft Visual C++ .NET 2002) and GLUT v3.7 (I downloaded from the OpenGL.org) are adequate to use in the Managed C++ extension/platform of Microsoft Visual C++ .NET 2002 - Windows XP Pro PC.
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

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();
}
//***Strucking Special 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);
}

int 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()
glutSpecialFunc(SpecialKeys);

return 0;
}

chemdog
02-16-2004, 03:36 AM
You left out a semicolon near the end.

SetupRC();
glutMainLoop(); // <- right here
glutSpecialFunc(SpecialKeys);

chemdog
02-16-2004, 03:38 AM
and you have a syntax error in the

glutIdleFunc(RenderScence);
^ should not have a c