G
Guest
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 Chan
==================================
// ---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 amount
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 Buffe
glLoadIdentity();
// Called to draw scen
void RenderScene(void
// Clear the windo
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
// Save matrix state and do the rotatio
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 Drawin
// Reset The Current Modelview Matri
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 vertice
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 shap
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 lin
glVertex3f (0, 0, 0)
glVertex3f (-0.2, 0.2, 0); //2nd verte
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 verte
glVertex3f (0, 0, 0)
glEnd(); // Finished drawing the last lin
glColor3f (1.0, 0.0, 0.0); //Set the color to re
glBegin(GL_TRIANGLES);
glVertex3f (0, 0, 0)
glVertex3f (0.5, 0.1, 0)
glVertex3f (0.2, 0.2, 0)
glEnd()
//return 0;
// Restore transformation
glPopMatrix()
// Flush drawing command
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 Windo
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 zer
if(h == 0
h = 1
// Set Viewport to window dimension
glViewport(0, 0, w, h)
// Reset projection matrix stac
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 stac
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;
}
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 Chan
==================================
// ---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 amount
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 Buffe
glLoadIdentity();
// Called to draw scen
void RenderScene(void
// Clear the windo
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
// Save matrix state and do the rotatio
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 Drawin
// Reset The Current Modelview Matri
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 vertice
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 shap
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 lin
glVertex3f (0, 0, 0)
glVertex3f (-0.2, 0.2, 0); //2nd verte
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 verte
glVertex3f (0, 0, 0)
glEnd(); // Finished drawing the last lin
glColor3f (1.0, 0.0, 0.0); //Set the color to re
glBegin(GL_TRIANGLES);
glVertex3f (0, 0, 0)
glVertex3f (0.5, 0.1, 0)
glVertex3f (0.2, 0.2, 0)
glEnd()
//return 0;
// Restore transformation
glPopMatrix()
// Flush drawing command
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 Windo
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 zer
if(h == 0
h = 1
// Set Viewport to window dimension
glViewport(0, 0, w, h)
// Reset projection matrix stac
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 stac
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;
}