Created
November 14, 2017 08:26
-
-
Save kevinmungai/5b8591a69fb4f4e22cbcf8fb482a305f to your computer and use it in GitHub Desktop.
Shows how to perform translation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** GL02Primitive.cpp: Vertex, Primitive and Color* Draw Simple 2D colored Shapes: quad, triangle and polygon.*/ | |
#include <windows.h> // for MS Windows | |
#include <GL/glut.h> // GLUT, include glu.h and gl.hvoid | |
initGL() { | |
glMatrixMode(GL_MODELVIEW); //Set Matrices to MODELVIEW to support transformations | |
glLoadIdentity(); | |
gluOrtho2D(0.0, 640.0, 0.0, 480.0); | |
glViewport(0,0,640,480); | |
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT); | |
} | |
void display() {//Draw diamond before translation | |
glBegin(GL_POLYGON); | |
glVertex2i(50,0); | |
glVertex2i(100,50); | |
glVertex2i(50,100); | |
glVertex2i(0,50); | |
glEnd();//peform translation | |
glTranslated(100, 100, 0.0); //x=+100, y=+100,z=+0//re-draw diamond after translation | |
glBegin(GL_POLYGON); | |
glVertex2i(50,0); | |
glVertex2i(100,50); | |
glVertex2i(50,100); | |
glVertex2i(0,50); | |
glEnd(); | |
glFlush(); | |
}/* Main function: GLUT runs as a console application starting at main() */ | |
int main(int argc, char** argv) { | |
glutInit(&argc, argv); // Initialize GLUT | |
glutCreateWindow("Simple Translation"); // Create window with the given title | |
glutInitWindowSize(640, 480); // Set the window's initial width & height | |
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner | |
initGL(); | |
glutDisplayFunc(display); | |
glutMainLoop(); // Enter the event-processing loop | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment