Advertisement
Guest User

Untitled

a guest
Sep 29th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * GL01Hello.cpp: Test OpenGL C/C++ Setup
  3.  */
  4. #include <windows.h>  // For MS Windows
  5. #include <GL/glut.h>  // GLUT, includes glu.h and gl.h'
  6. #include <iostream>
  7.  
  8. /* Handler for window-repaint event. Call back when the window first appears and
  9.    whenever the window needs to be re-painted. */
  10. void display() {
  11.    int const win_width  = glutGet(GLUT_WINDOW_WIDTH);
  12.    int const win_height = glutGet(GLUT_WINDOW_HEIGHT);
  13.  
  14.    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
  15.    glClear(GL_COLOR_BUFFER_BIT);         // Clear the color buffer; this clears the whole window regardless of the set viewport
  16.  
  17.    glViewport(0, 0, win_width, win_height); // we can set the viewport after clearing
  18.  
  19.    // Draw a Red 1x1 Square centered at origin
  20.    glBegin(GL_QUADS);              // Each set of 4 vertices form a quad
  21.       glColor3f(1.0f, 0.0f, 0.0f); // Red
  22.       glVertex2f(-0.5f, -0.5f);    // x, y
  23.       glVertex2f( 0.5f, -0.5f);
  24.       glVertex2f( 0.5f,  0.5f);
  25.       glVertex2f(-0.5f,  0.5f);
  26.    glEnd();
  27.  
  28.    glutSwapBuffers();
  29. }
  30.  
  31. /* Main function: GLUT runs as a console application starting at main()  */
  32. int main(int argc, char** argv) {
  33.     std::cout<<"Hello, world!!"<<std::endl;
  34.    glutInit(&argc, argv);                 // Initialize GLUT
  35.  
  36.    glutInitWindowSize(320, 320);   // Set the window's initial width & height
  37.    glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
  38.    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  39.  
  40.    glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
  41.  
  42.    glutDisplayFunc(display); // Register display callback handler for window re-paint
  43.  
  44.    glutMainLoop();           // Enter the infinitely event-processing loop
  45.  
  46.    return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement