Last active
November 16, 2017 08:38
-
-
Save kevinmungai/6609cf5310553211f069bc59f446182b to your computer and use it in GitHub Desktop.
translation leading to checkers pattern
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; | |
// to support translation, scaling and transformation | |
// use the GL_MODELVIEW Matrix | |
glMatrixMode(GL_MODELVIEW); // To operate on Model-View matrix | |
glLoadIdentity(); // Reset the model-view matrix | |
GLint colorCode = 1; | |
for (y=0.0;y<=1000.0;y=y+50.0) { | |
for (x=0.0;x<=1000.0;x=x+50.0) { | |
glLoadIdentity(); // Reset the model-view matrix | |
// we are passing the values for x, y and no value for z to glTranslated | |
// note it's glTranslate'd' for double | |
glTranslated(x, y, 0.0); // Translate Right and up | |
if (colorCode == 1) { | |
colorCode = 0; | |
glColor3f(1.0, 1.0, 1.0); | |
} else { | |
colorCode = 1; | |
glColor3f(0.0, 0.0, 0.0); | |
} | |
glBegin(GL_POLYGON); // Each set of 4 vertices form a quad | |
glVertex2i(0,0); | |
glVertex2i(0,50); | |
glVertex2i(50,50); | |
glVertex2i(50,0); | |
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