Created
September 23, 2015 08:07
-
-
Save bitbrain/e06aa2078578679c6fcf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* OpenGL module | |
* Assessment 5 | |
* | |
* author: Miguel Gonzalez <[email protected]> | |
*/ | |
#include <GL/glut.h> | |
int number = 12; | |
GLubyte wb[2]={0x00, 0xFF}; | |
GLubyte check[1024]; | |
void init() | |
{ | |
for (int i=0;i<(number*number);i++) | |
{ | |
for (int j=0; j<number; j++) | |
{ | |
check[i*number+j] = wb[(i/number+j)%2]; | |
} | |
} | |
} | |
void drawCheckerboard() | |
{ | |
glRasterPos3f(0.0f, 0.0f, 0.0f); | |
glColor3f(1.0f, 0.0f, 0.0f); | |
glBitmap(number*number, number*number, 0.0, 0.0, 0.0, 0.0, check); | |
glRasterPos3f(0.0f, 0.0f, 0.0f); | |
glColor3f(0.0f, 1.0f, 0.0f); | |
glEnable(GL_COLOR_LOGIC_OP); | |
glLogicOp(GL_XOR); | |
glBitmap(number*number, number*number, -4.0, 4.0, 0.0, 0.0, check); | |
glDisable(GL_COLOR_LOGIC_OP); | |
glRasterPos3f(-1.0f, 1.0f, 0.0f); | |
glCopyPixels(0.0f, 0.0f, 128.0f, 128.0f, GL_COLOR); | |
} | |
void display() | |
{ | |
glMatrixMode(GL_MODELVIEW); | |
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glLoadIdentity(); | |
glPushMatrix(); | |
drawCheckerboard(); | |
glPopMatrix(); | |
glFlush(); | |
glutSwapBuffers(); | |
} | |
void reshape(GLsizei w, GLsizei h) | |
{ | |
glViewport (0, 0, (GLsizei) w, (GLsizei) h); | |
glLoadIdentity(); | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
init(); | |
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); | |
glutInitWindowSize(800, 600); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow("OpenGL - Assessment 4"); | |
glDisable(GL_LIGHTING); | |
glEnable(GL_COLOR_LOGIC_OP); | |
glutReshapeFunc(reshape); | |
glutDisplayFunc(display); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment