Oracle
New member
Hey guys me again cause problems, i was trying out some tutorials and decided to go off on a tangent by making my triangles spin.
Ive been really good and havent posted here untill i got really stuck. The programs runs fine except the to quote Mc bain " the triangles they do nothing!"
I wish i knew wherei was going wrong below is the code:
#include <windows.h>
#include <math.h>
#include <gl/glut.h>
#define PI 3.1415926535898
float Xpos = 0.5;
float Ypos = 0.8;
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ;
glShadeModel(GL_SMOOTH);
}
void reshape(int w, int h)
{
//control the 2d viewport
//glViewport(0, 0, (GLsizei) w, (GLsizei) h);
//control the 3d clipping volume
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5, 0.5, -1.0, 1.0, 0.5, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); //clear colour buffer to black
const float colour1[] = {1.0, 0.0, 0.0}; //red
glLoadIdentity();
glTranslatef(0.0, 0.0, -1.0);
glColor3fv(colour1);
glutWireCube(1.0);
if(Xpos <= 0.005&&Xpos >= -0.005&&Ypos <= 0.005&&Ypos >= -0.005)//moving code
glShadeModel(GL_SMOOTH);
else
glShadeModel(GL_FLAT);
///////////////triangle (non)////////////////////
glShadeModel(GL_SMOOTH);
glBegin(GL_POLYGON);
glColor3f(1.0f,.0f,0.0f);
glVertex3f(-0.6f,-0.6,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0,0.6,0.0f);
glColor3f(0.5f,1.0f,0.5f);
glVertex3f(0.0,-0.6,0.0f);
glEnd();
//////////////////////////////////
////////////triangle (move)////////////////////
glShadeModel(GL_SMOOTH);
glTranslatef(Xpos,Ypos,0.0f);//translate the polygon on the x &y axis
glBegin(GL_POLYGON);
glColor3f(0.5f,0.0f,0.5f);
glVertex3f(0.0f,-0.6f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,0.6f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(0.6f,-0.6f,0.0f);
glEnd();
///////////////////////////////////
glEnd();
glutSwapBuffers(); //update screen
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case'w':
Xpos = Xpos - 0.05f;
glutPostRedisplay();
break;
case's':
Xpos = Xpos + 0.05f;
glutPostRedisplay();
break;
case'a':
Ypos = Ypos + 0.05f;
glutPostRedisplay();
break;
case'd':
Ypos = Ypos - 0.05f;
glutPostRedisplay();
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ;
glutInitWindowSize (500, 500) ;
glutInitWindowPosition (100, 100) ;
glutCreateWindow ("Spinny!") ;
init() ; //initialise opengl settings
glutDisplayFunc (display); //set up call back for display
glutReshapeFunc (reshape); //set up call back for reshape
glutMainLoop () ;
return 0 ;
}
Ive been really good and havent posted here untill i got really stuck. The programs runs fine except the to quote Mc bain " the triangles they do nothing!"
I wish i knew wherei was going wrong below is the code:
#include <windows.h>
#include <math.h>
#include <gl/glut.h>
#define PI 3.1415926535898
float Xpos = 0.5;
float Ypos = 0.8;
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ;
glShadeModel(GL_SMOOTH);
}
void reshape(int w, int h)
{
//control the 2d viewport
//glViewport(0, 0, (GLsizei) w, (GLsizei) h);
//control the 3d clipping volume
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5, 0.5, -1.0, 1.0, 0.5, 10.0);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); //clear colour buffer to black
const float colour1[] = {1.0, 0.0, 0.0}; //red
glLoadIdentity();
glTranslatef(0.0, 0.0, -1.0);
glColor3fv(colour1);
glutWireCube(1.0);
if(Xpos <= 0.005&&Xpos >= -0.005&&Ypos <= 0.005&&Ypos >= -0.005)//moving code
glShadeModel(GL_SMOOTH);
else
glShadeModel(GL_FLAT);
///////////////triangle (non)////////////////////
glShadeModel(GL_SMOOTH);
glBegin(GL_POLYGON);
glColor3f(1.0f,.0f,0.0f);
glVertex3f(-0.6f,-0.6,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0,0.6,0.0f);
glColor3f(0.5f,1.0f,0.5f);
glVertex3f(0.0,-0.6,0.0f);
glEnd();
//////////////////////////////////
////////////triangle (move)////////////////////
glShadeModel(GL_SMOOTH);
glTranslatef(Xpos,Ypos,0.0f);//translate the polygon on the x &y axis
glBegin(GL_POLYGON);
glColor3f(0.5f,0.0f,0.5f);
glVertex3f(0.0f,-0.6f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,0.6f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(0.6f,-0.6f,0.0f);
glEnd();
///////////////////////////////////
glEnd();
glutSwapBuffers(); //update screen
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case'w':
Xpos = Xpos - 0.05f;
glutPostRedisplay();
break;
case's':
Xpos = Xpos + 0.05f;
glutPostRedisplay();
break;
case'a':
Ypos = Ypos + 0.05f;
glutPostRedisplay();
break;
case'd':
Ypos = Ypos - 0.05f;
glutPostRedisplay();
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ;
glutInitWindowSize (500, 500) ;
glutInitWindowPosition (100, 100) ;
glutCreateWindow ("Spinny!") ;
init() ; //initialise opengl settings
glutDisplayFunc (display); //set up call back for display
glutReshapeFunc (reshape); //set up call back for reshape
glutMainLoop () ;
return 0 ;
}