Last active
November 14, 2017 08:50
-
-
Save kevinmungai/dbe593963b8bf196e0fcb215f1e10d6c to your computer and use it in GitHub Desktop.
performing translation with OpenGL
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.h/* Initialize OpenGL Graphics */ | |
void initGL() { | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
gluOrtho2D(0.0, 1000.0, 0.0, 1000.0); | |
glViewport(0,0,1000,1000); | |
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black and opaque | |
} | |
/* Handler for window-repaint event. Call back when the window first appears andwhenever the window needs to be re-painted. */ | |
void display() { | |
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current clearing color | |
glLineWidth(4.0); | |
GLdouble x,y; | |
glMatrixMode(GL_MODELVIEW); // To operate on Model-View matrix | |
glLoadIdentity(); // Reset the model-view matrix | |
for (y=0.0;y<=1000.0;y=y+100.0) { | |
for (x=0.0;x<=1000.0;x=x+100.0) { | |
glLoadIdentity(); // Reset the model-view matrix | |
glTranslated(x, y, 0.0); // Translate Right and up | |
glBegin(GL_POLYGON); // Each set of 4 vertices form a quad | |
glColor3f(0.0, 0.0, 0.0); | |
glVertex2i(50,0); | |
glVertex2i(100,50); | |
glVertex2i(50,100); | |
glVertex2i(0,50); | |
glEnd(); | |
} | |
} | |
glFlush(); // Render now | |
} | |
/* Main function: GLUT runs as a console application starting at main() */ | |
int main(int argc, char** argv) { | |
glutInit(&argc, argv); // Initialize GLUT | |
glutCreateWindow("Performing Transation"); // 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); // Register callback handler for window re-paint event // Our own OpenGL initialization | |
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