Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Template1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <math.h>
- #include <Windows.h>
- #include "include\GL\GL.H"
- #include "include\GL\GLU.H"
- #include "include\GL\glut.h"
- #include "Template1.h"
- using namespace std;
- double rotate_y = 0;
- double rotate_x = 0;
- void MyDisplay(void) {
- glLoadIdentity();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glTranslated(0.0, 0.0, -7.0);
- glRotatef(rotate_x, 1.0, 0.0, 0.0);
- glRotatef(rotate_y, 0.0, 1.0, 0.0);
- //back
- glBegin(GL_POLYGON);
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex3d(1, 1, 1);
- glVertex3d(-1, 1, 1);
- glVertex3d(-1, -1, 1);
- glVertex3d(1, -1, 1);
- glEnd();
- //front
- glBegin(GL_POLYGON);
- glColor3f(0.0f, 1.0f, 0.0f);
- glVertex3d(1, 1, -1);
- glVertex3d(-1, 1, -1);
- glVertex3d(-1, -1, -1);
- glVertex3d(1, -1, -1);
- glEnd();
- //right side
- glBegin(GL_POLYGON);
- glColor3f(0.0f, 0.0f, 1.0f);
- glVertex3d(1, 1, -1);
- glVertex3d(1, 1, 1);
- glVertex3d(1, -1, 1);
- glVertex3d(1, -1, -1);
- glEnd();
- //left side
- glBegin(GL_POLYGON);
- glColor3f(1.0f, 1.0f, 0.0f);
- glVertex3d(-1, 1, -1);
- glVertex3d(-1, 1, 1);
- glVertex3d(-1, -1, 1);
- glVertex3d(-1, -1, -1);
- glEnd();
- //top
- glBegin(GL_POLYGON);
- glColor3f(1.0f, 0.0f, 1.0f);
- glVertex3d(1, 1, -1);
- glVertex3d(-1, 1, -1);
- glVertex3d(-1, 1, 1);
- glVertex3d(1, 1, 1);
- glEnd();
- //bottom
- glBegin(GL_POLYGON);
- glColor3f(0.0f, 1.0f, 1.0f);
- glVertex3d(1, -1, -1);
- glVertex3d(-1, -1, -1);
- glVertex3d(-1, -1, 1);
- glVertex3d(1, -1, 1);
- glEnd();
- glPopMatrix();
- glFlush();
- //necessary for GLU_DOUBLE displayMode
- //glutSwapBuffers();
- }
- void keyboard(int key, int x, int y) {
- if (key == GLUT_KEY_RIGHT)
- rotate_y += 5;
- else if (key == GLUT_KEY_LEFT)
- rotate_y -= 5;
- else if (key == GLUT_KEY_UP)
- rotate_x -= 5;
- else if (key == GLUT_KEY_DOWN)
- rotate_x += 5;
- // Request display update
- glutPostRedisplay();
- }
- void MyInit(void) {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glViewport(0, 500, 500, 500);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60, 1, 1, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glDrawBuffer(GL_BACK);
- glEnable(GL_DEPTH_TEST);
- }
- void Rotate(int){}
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);//single buffer and RGBA
- glutInitWindowSize(500, 500);//initial window size
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Cube");//create widnow, hello title bar
- MyInit();
- glutDisplayFunc(MyDisplay);
- glutSpecialFunc(keyboard);
- glutMainLoop();//enter main loop and process events
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement