Skip to content

Instantly share code, notes, and snippets.

@kevinmungai
Last active November 7, 2017 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmungai/808b087c6e98f11c29734473d80fbc3a to your computer and use it in GitHub Desktop.
Save kevinmungai/808b087c6e98f11c29734473d80fbc3a to your computer and use it in GitHub Desktop.
// lab assignment
// Triangles Pattern
// Also included is Varying Sizes.
#include <windows.h> // for MS Windows
#include <GL/glut.h> // GLUT, include glu.h and gl.h
#include <GL/gl.h>
/* Initialize OpenGL Graphics */
void initGL();
void display ();
void initGL() {
// Set "clearing" or background color
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black and opaque BackGround
gluOrtho2D(80.0, 380.0, 0.0, 160.0); // World View gluOrtho2d(left, right, bottom, top);
glViewport(0, 0, 640, 480); // Is the View Port glViewport(left, bottom, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
GLdouble offset = 30;
GLdouble x, y;
glColor3f(0.0, 0.0, 0.0);
for (y = 0.0; y <= 160.0; y += 40.0) {
if (offset == 0) {
offset = 30;
} else {
offset = 0;
}
for (x = 50.0; x <= 380.0; x += 60.0) {
glBegin(GL_TRIANGLES);
glVertex2d(x + offset, y);
glVertex2d(x + 60.0 + offset, y);
glVertex2d(x + 30.0 + offset, y + 40.0);
glEnd();
}
}
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(" Triangles Assignment"); // 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
glutDisplayFunc(display); // Register callback handler for window re-paint event
initGL(); // 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