This semester I’m taking a Computer Graphics course focused around OpenGL. The professor spend his lectures talking about theoretical’s and concepts. Never shows any code what-so-ever. I’ve never used C before, but I’m pretty familiar with C++/C#. I’ve been coding in VS2008pro.
For our second assignment he wants us to draw a sphere using triangle fans and quad strips. While he did kind of talk about what fans and strips are he never showed us how to do it. So after digging on the net, I found the method and played around with it for a bit.
I’ve been trying to use a for loop to create my fan for me, using some trig functions, but for whatever the reason, I cannot.
Here’s what I’ve been trying to do.
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display()
{
glBegin (GL_TRIANGLE_FAN);
glVertex3f(0., 1.0, 0.);
for (int i=0; i<20; i++)
{
float angle = 2. * (float)i*3.14/(float)20;
glVertex3f(0.5*cos(angle), 0.0, 0.5*sin(angle));
}
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport (0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
The errors I get are all similar to this, just moving down token by token telling me I have a syntax error.
Error 1 error C2143: syntax error : missing ‘;’ before ‘type’ line 33
I’ve searched and searched for a syntax error but I can’t find one. I thought that perhaps you couldn’t have a for loop within a glBegin()/glEnd() sequence, but I see it as an example in my text book. Not to mention that a for loop will not work anywhere within my code.
Anyway, if any of you can help fill me in on what I’m doing wrong, I’d greatly appreciate it.
Thanks.