Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GLParty3D.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "glut.h"
- // Function prototypes
- void initOpenGL();
- void keyboard(unsigned char key, int x, int y);
- void idle();
- void draw();
- void drawAxisLines();
- // Global variables
- float xpos = 0.f;
- float ypos = 2.f;
- float zpos = -35.f;
- float xrot = 0.f;
- float yrot = 0.f;
- float zrot = 0.f;
- // Constant tri-force vertex array
- const GLfloat triforce[48*3] = {
- // The closest front faces of the triforce
- -57.5f, 0.f, 0.f,
- 57.5f, 0.f, 0.f,
- 0.f, 100.f, 0.f,
- -115.f, -100.f, 0.f,
- 0.f, -100.f, 0.f,
- -57.f, 0.f, 0.f,
- 0.f, -100.f, 0.f,
- 115.f, -100.f, 0.f,
- 57.f, 0.f, 0.f,
- // The "left" side of the triforce
- -115.f, -100.f, 0.f,
- -115.f, -100.f, 20.f,
- 0.f, 100.f, 0.f,
- -115.f, -100.f, 20.f,
- 0.f, 100.f, 0.f,
- 0.f, 100.f, 20.f,
- // The "right" side of the triforce
- 115.f, -100.f, 0.f,
- 115.f, -100.f, 20.f,
- 0.f, 100.f, 0.f,
- 115.f, -100.f, 20.f,
- 0.f, 100.f, 0.f,
- 0.f, 100.f, 20.f,
- // The "bottom" of the triforce
- -115.f, -100.f, 0.f,
- -115.f, -100.f, 20.f,
- 115.f, -100.f, 0.f,
- -115.f, -100.f, 20.f,
- 115.f, -100.f, 0.f,
- 115.f, -100.f, 20.f,
- // The "back" face of the triforce
- -57.5f, 0.f, 20.f,
- 57.5f, 0.f, 20.f,
- 0.f, 100.f, 20.f,
- -115.f, -100.f, 20.f,
- 0.f, -100.f, 20.f,
- -57.5f, 0.f, 20.f,
- 0.f, -100.f, 20.f,
- 115.f, -100.f, 20.f,
- 57.5f, 0.f, 20.f,
- // The inside, lower left
- 0.f, -100.f, 0.f,
- 0.f, -100.f, 20.f,
- 57.5f, 0.f, 0.f,
- 0.f, -100.f, 20.f,
- 57.5f, 0.f, 0.f,
- 57.5f, 0.f, 20.f,
- // The inside, lower right
- 0.f, -100.f, 0.f,
- 0.f, -100.f, 20.f,
- -57.5f, 0.f, 0.f,
- 0.f, -100.f, 20.f,
- -57.5f, 0.f, 0.f,
- -57.5f, 0.f, 20.f,
- };
- // HOVEDPROGRAMMET //
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(600,400);
- glutCreateWindow("CV: movY FR: rotX GT: rotY HY: rotz");
- glutIdleFunc(idle);
- glutDisplayFunc(draw);
- glutKeyboardFunc(keyboard);
- initOpenGL();
- glutMainLoop();
- return 0;
- }
- void initOpenGL()
- {
- gluPerspective(
- 50,
- 600.f/400.f,
- 0.1,
- 1000
- );
- glViewport(0,0,600,400);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_VERTEX_ARRAY);
- glDisable(GL_COLOR_ARRAY);
- glClearColor(0.f, 1.f, 0.5f, 1.f);
- glMatrixMode(GL_MODELVIEW);
- }
- void keyboard(unsigned char key, int x, int y)
- {
- key = towlower(key);
- if (key == 'p')
- exit(0);
- else if (key == 'w')
- zpos += 1.f;
- else if (key == 's')
- zpos -= 1.f;
- else if (key == 'a')
- xpos += 1.f;
- else if (key == 'd')
- xpos -= 1.f;
- else if (key == 'q')
- ypos -= 1.f;
- else if (key == 'z')
- ypos += 1.f;
- }
- void idle()
- {
- //xrot += 0.5f;
- yrot += 0.5f;
- glutPostRedisplay();
- }
- void draw()
- {
- glPushMatrix();
- glTranslatef(xpos, ypos, zpos);
- glRotatef(xrot, 1.f, 0.f, 0.f);
- glRotatef(yrot, 0.f, 1.f, 0.f);
- glRotatef(zrot, 0.f, 0.f, 1.f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //glColor3f(1.f, 0.f, 0.f);
- //glutWireTeapot(1);
- glEnable(GL_VERTEX_ARRAY);
- glEnable(GL_COLOR_ARRAY);
- //drawAxisLines();
- glDisable(GL_COLOR_ARRAY);
- glColor3f(1.f, 1.f, 0.f);
- glScalef(0.1f, 0.1f, 0.1f);
- glVertexPointer(3, GL_FLOAT, 0, &triforce);
- glDrawArrays(GL_TRIANGLES, 0, 48);
- glDisable(GL_VERTEX_ARRAY);
- glPopMatrix();
- glutSwapBuffers();
- }
- void drawAxisLines()
- {
- // This function expects GL_VERTEX_ARRAY to be enabled.
- glLineWidth(5.f);
- GLfloat verts[] = {
- -100.f, 0.f, 0.f,
- 100.f, 0.f, 0.f,
- 0.f, -100.f, 0.f,
- 0.f, 100.f, 0.f,
- 0.f, 0.f, -100.f,
- 0.f, 0.f, 100.f,
- };
- GLfloat color[] = {
- 0.f, 0.f, 1.f,
- 0.f, 0.f, 1.f,
- 0.f, 1.f, 0.f,
- 0.f, 1.f, 0.f,
- 1.f, 0.f, 0.f,
- 1.f, 0.f, 0.f,
- };
- // Point to the color array
- glColorPointer(3, GL_FLOAT, 0, &color);
- // Point to the vertex array
- glVertexPointer(3, GL_FLOAT, 0, &verts);
- //OpenGL now knows that "verts" is: X * (3 * sizeof(GL_FLOAT))
- // Draw the array
- glDrawArrays(GL_LINES, 0, 6);
- // OpenGL now knows that the size of "verts" is 6*3*sizeof(GL_FLOAT)
- glLineWidth(1.f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement