Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <GL/glut.h> // GLUT, includes glu.h and gl.h
- float randomFloat()
- {
- float r = (float)rand() / (float)RAND_MAX;
- return r;
- }
- void display() {
- int x , y=0;
- glClearColor(1.0f, 1.0f, 0.0f, 1.0f); // Set background color to black and opaque
- glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
- // glScalef( 1.1, 1.1 ,1);
- // glTranslatef(1.0f, -0.5f, 0.0f);
- glBegin(GL_TRIANGLES); // Each set of 4 vertices form a quad
- // Red
- /*************************************************************/
- glColor3f(randomFloat(), 0.0f, 0.0f); // Red
- glVertex2i(50, 50);
- glColor3f(0.0f, randomFloat(), 0.0f); // Green
- glVertex2i(200, 50);
- glColor3f(0.0f, 0.0f, randomFloat()); // Blue
- glVertex2i(100 ,100);
- /***********************************************************/
- glEnd();
- glFlush(); // Render now
- }
- void mouse(int button, int state, int x, int y) {
- if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // Pause/resume
- // glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
- // glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
- display() ;
- }
- }
- /* Main function: GLUT runs as a console application starting at main() */
- int main(int argc, char** argv) {
- glutInit(&argc, argv); // Initialize GLUT
- glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
- glutInitWindowSize(320, 320); // Set the window's initial width & height
- glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
- glutDisplayFunc(display); // Register display callback handler for window re-paint
- gluOrtho2D(0, 320, 0, 320);
- /////////////////////////////////////////////
- // glEnable(GL_LINE_STIPPLE); glLineStipple(1,0x00AA);
- // glutMouseFunc(mouse); //MOUSE
- srand(time(NULL));
- glutMainLoop(); // Enter the infinitely event-processing loop
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement