Advertisement
shardy

Untitled

Oct 2nd, 2013
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.17 KB | None | 0 0
  1. //OPENGL 3.2 EXAMPLE
  2.  
  3. //NB: DEPRECATED COMMANDS WILL NOT FUNCTION.
  4. //SEE OPENGL QUICK REFERENCE FOR DETAILS
  5.  
  6. #include <windows.h>        // Header File For Windows
  7. //#include <gl\gl.h>            // Header File For The OpenGL32 Library  
  8. //#include <gl\glu.h>           // Header File For The GLu32 Library
  9. //-- OPENGL FILES INCLUDED IN GLEW see below
  10.  
  11. #include <iostream>
  12. using namespace std;
  13.  
  14. #include <math.h>     //sin and cos included in this header file.
  15.  
  16. #include "console.h"        //Used for displaying the console
  17. #include "shaders/Shader.h"   // include shader header file, this is not part of OpenGL
  18.                               //Shader.h has been created using common glsl structure
  19.  
  20. //--- OpenGL --- The OpenGL Extension Wrangler Library
  21. #include "gl/glew.h"
  22. #include "gl/wglew.h"
  23. #pragma comment(lib, "glew32.lib")
  24. //--------------
  25.  
  26. unsigned int m_vaoID;       // vertex array object
  27. unsigned int m_vboID[2];    // two VBOs - used for colours and vertex data
  28.  
  29. const int numOfVerts = 12;  //6 vertices (3 for each tri (x, y, z))
  30. const int numOfTris = 4;    //2 triangles make 1 square
  31. float verts[36];            //3*6=18 verts (x,y,z for each vert = 1 coord)
  32. float cols[36];             //same as above for unique colours
  33.  
  34.  
  35. //unsigned int m_vaoID2;
  36. //unsigned int m_vboID2[2];
  37. //const int numbOfPoints = 4;
  38. //float line_vertex[12];        //12 for two lines, 6 for one, XYZ
  39. //float line_col[12];           //As above for colours RGB
  40.  
  41.  
  42. Shader myShader;            //shader object
  43.  
  44. ConsoleWindow console;
  45.  
  46. int screenWidth=600, screenHeight=600; //changed from 480x480px
  47.  
  48. //OPENGL FUNCTION PROTOTYPES
  49. void display();             //called in winmain to draw everything to the screen
  50. void init();                //called in winmain when the program starts.
  51. void createGeometry();      //used to create Vertex Array Objects
  52. void reshape(int width, int height);
  53.  
  54. /*************    START OF OPENGL FUNCTIONS   ****************/
  55.  
  56. void reshape(int width, int height)         // Resize the OpenGL window
  57. {
  58.     int b = 50; //border of 50px
  59.  
  60.     screenWidth = width;
  61.     screenHeight = height;
  62.  
  63.     glViewport(0+b,0+b,width-(b*2),height-(b*2));   // set Viewport dimensions
  64. }
  65.  
  66. void display()                                 
  67. {
  68.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  69.  
  70.     glUseProgram(myShader.handle());  // use the shader
  71.  
  72.     //draw objects
  73.     glBindVertexArray(m_vaoID);     // select VAO
  74.    
  75.     //draw some geometry | int points to where to start in array
  76.     glDrawArrays(GL_TRIANGLES, 0, numOfVerts); //change to 3 for half the first triangle
  77.  
  78.         //glVertexPointer(2, GL_FLOAT,4,&line_vertex);
  79.         //glDrawArrays(GL_LINES,0,numbOfPoints);
  80.  
  81.         //Enlarge ALL the Points
  82.         glEnable(GL_POINT_SMOOTH);
  83.         glPointSize(50);
  84.         glDrawArrays(GL_POINTS,0, (numOfVerts/2)); //divied the numOfVerts by 2 so only first 12 get enlarged
  85.         glPointSize(25);
  86.         glDrawArrays(GL_POINTS,6, (numOfVerts/2)); //same again but start at 6, only last 6 get enlarged
  87.            
  88.        
  89.  
  90.     // Done
  91.     glBindBuffer(GL_ARRAY_BUFFER, 0);  //unbind the buffer
  92.    
  93.     glBindVertexArray(0); //unbind the vertex array object
  94.    
  95.     glUseProgram(0); //turn off the current shader
  96. }
  97.  
  98. void createGeometry()
  99. {
  100.     //First simple object
  101.     float dim = 0.5;
  102.     //Triangle 1
  103.     //points    X                   Y                   Z
  104.     verts[0] = -dim;  verts[ 1] = -dim;  verts[ 2] = -dim; //Point 1
  105.     verts[3] = -dim;  verts[ 4] =  dim;  verts[ 5] = -dim; //Point 2
  106.     verts[6] =  dim;  verts[ 7] =  dim;  verts[ 8] = -dim; //Point 3
  107.     //Above is same as writing all values in 1 array {..,...,...} etc
  108.    
  109.     //Triangle 2
  110.     //points    X                   Y                   Z
  111.     verts[ 9] =  dim;  verts[10] = -dim;  verts[11] = -dim; //Point 4
  112.     verts[12] = -dim;  verts[13] = -dim;  verts[14] = -dim; //Point 1
  113.     verts[15] =  dim;  verts[16] =  dim;  verts[17] = -dim; //Point 3
  114.  
  115.  
  116.     //colour    R               G               B
  117.     cols[ 0] = 1.0;  cols[ 1] = 0.0;  cols[ 2] = 1.0; //Point1 R: 1,0,0
  118.     cols[ 3] = 0.0;  cols[ 4] = 1.0;  cols[ 5] = 1.0; //Point2 G: 0,1,0
  119.     cols[ 6] = 1.0;  cols[ 7] = 1.0;  cols[ 8] = 0.0; //Point3 B: 0,0,1
  120.  
  121.     //colour2   R               G               B
  122.     cols[ 9] = 0.0;  cols[10] = 1.0;  cols[11] = 1.0; //Point4
  123.     cols[12] = 1.0;  cols[13] = 0.0;  cols[14] = 1.0; //Point5
  124.     cols[15] = 1.0;  cols[16] = 1.0;  cols[17] = 0.0; //Point6
  125.  
  126.     //Second simple object
  127.     float dim2 = 0.2; //make bigger than 0.5 to overlap frist drawn shape.
  128.     //Triangle 1 (centered)
  129.     //points    X                   Y                   Z
  130.     //verts[18] = -dim2;  verts[19] = -dim2;  verts[20] = -dim2; //Point 1
  131.     //verts[21] = -dim2;  verts[22] =  dim2;  verts[23] = -dim2; //Point 2
  132.     //verts[24] =  dim2;  verts[25] =  dim2;  verts[26] = -dim2; //Point 3
  133.     //
  134.     ////Triangle 2
  135.     ////points  X                   Y                   Z
  136.     //verts[27] =  dim2;  verts[28] = -dim2;  verts[29] = -dim2; //Point 4
  137.     //verts[30] = -dim2;  verts[31] = -dim2;  verts[32] = -dim2; //Point 1
  138.     //verts[33] =  dim2;  verts[34] =  dim2;  verts[35] = -dim2; //Point 3
  139.  
  140.     float a = 0.25, b = 0.75; //0.5 & 1.0 to show viewport.
  141.  
  142.     //points    X                   Y                   Z
  143.     verts[18] = a;  verts[19] = a;  verts[20] = -dim2; //Point 1
  144.     verts[21] = a;  verts[22] = b;  verts[23] = -dim2; //Point 2
  145.     verts[24] = b;  verts[25] = b;  verts[26] = -dim2; //Point 3
  146.    
  147.     //Triangle 2 (offset)
  148.     //points    X                   Y                   Z
  149.     verts[27] = b;  verts[28] = a;  verts[29] = -dim2; //Point 4
  150.     verts[30] = a;  verts[31] = a;  verts[32] = -dim2; //Point 1
  151.     verts[33] = b;  verts[34] = b;  verts[35] = -dim2; //Point 3
  152.  
  153.     //colour    R               G               B
  154.     cols[18] = 1.0;  cols[19] = 0.0;  cols[20] = 0.0; //Point1 R: 1,0,0
  155.     cols[21] = 0.0;  cols[22] = 1.0;  cols[23] = 0.0; //Point2 G: 0,1,0
  156.     cols[24] = 0.0;  cols[25] = 0.0;  cols[26] = 1.0; //Point3 B: 0,0,1
  157.  
  158.     //colour2   R               G               B
  159.     cols[27] = 1.0;  cols[28] = 0.0;  cols[29] = 0.0; //Point4
  160.     cols[30] = 0.0;  cols[31] = 1.0;  cols[32] = 0.0; //Point5
  161.     cols[33] = 0.0;  cols[34] = 0.0;  cols[35] = 1.0; //Point6
  162.  
  163.        
  164.     // VAO allocation
  165.     glGenVertexArrays(1, &m_vaoID);
  166.  
  167.     // First VAO setup
  168.     glBindVertexArray(m_vaoID);
  169.    
  170.     glGenBuffers(2, m_vboID);
  171.    
  172.     glBindBuffer(GL_ARRAY_BUFFER, m_vboID[0]);
  173.     //initialises data storage of vertex buffer object          //verts or line_vertex
  174.     glBufferData(GL_ARRAY_BUFFER, numOfVerts*3*sizeof(GLfloat), verts, GL_STATIC_DRAW);
  175.  
  176.  
  177.     //draw line | x1,y1,z1 x2,y2,z2
  178.     //float line_vertex[]=
  179.     //{
  180.     //  -0.75, -0.75, 0.7, //line 1
  181.     //   0.25,  0.25, 0.7,
  182.     //  -0.75,  0.75, 0.7, //line 2
  183.     //      0,     0, 0.7
  184.     //};
  185.     //float line_col[]=
  186.     //{
  187.     //  1,0,0,0,0,1,
  188.     //  0,1,0,1,0,0
  189.     //};
  190.  
  191.  
  192.     GLint vertexLocation= glGetAttribLocation(myShader.handle(), "in_Position");
  193.     glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
  194.     glEnableVertexAttribArray(vertexLocation);
  195.  
  196.     glBindBuffer(GL_ARRAY_BUFFER, m_vboID[1]);
  197.     glBufferData(GL_ARRAY_BUFFER, numOfVerts*3*sizeof(GLfloat), cols, GL_STATIC_DRAW);
  198.     GLint colorLocation= glGetAttribLocation(myShader.handle(), "in_Color");
  199.     glVertexAttribPointer(colorLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
  200.     glEnableVertexAttribArray(colorLocation);
  201.  
  202.     glBindBuffer(GL_ARRAY_BUFFER, 0);
  203.  
  204.     glEnableVertexAttribArray(0);
  205.  
  206.     glBindVertexArray(0);
  207. }
  208.  
  209.  
  210. void init()
  211. {
  212.     //(1,1,1,0) to (0,0,0,0) is white to black background.
  213.     glClearColor(0.0,0.0,0.0,0.0);                      //sets the clear colour to yellow
  214.                     //glClear(GL_COLOR_BUFFER_BIT) in the display function//will clear the buffer to this colour.
  215.  
  216.     // Shaders
  217.     if(!myShader.load("BasicView", "glslfiles/basic.vert", "glslfiles/basic.frag"))
  218.     {
  219.         cout << "failed to load shader" << endl;
  220.     }                          
  221.  
  222.     createGeometry();
  223.  
  224.     glEnable(GL_DEPTH_TEST);
  225. }
  226.  
  227. /**************** END OPENGL FUNCTIONS *************************/
  228.  
  229. //WIN32 functions
  230. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   // Declaration For WndProc
  231. void KillGLWindow();                                    // releases and destroys the window
  232. bool CreateGLWindow(char* title, int width, int height); //creates the window
  233. int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int);  // Win32 main function
  234.  
  235. //win32 global variabless
  236. HDC         hDC=NULL;       // Private GDI Device Context
  237. HGLRC       hRC=NULL;       // Permanent Rendering Context
  238. HWND        hWnd=NULL;      // Holds Our Window Handle
  239. HINSTANCE   hInstance;      // Holds The Instance Of The Application
  240.  
  241.  
  242. /******************* WIN32 FUNCTIONS ***************************/
  243. int WINAPI WinMain( HINSTANCE   hInstance,          // Instance
  244.                     HINSTANCE   hPrevInstance,      // Previous Instance
  245.                     LPSTR       lpCmdLine,          // Command Line Parameters
  246.                     int         nCmdShow)           // Window Show State
  247. {
  248.     console.Open();
  249.    
  250.     MSG     msg;                                    // Windows Message Structure
  251.     bool    done=false;                             // Bool Variable To Exit Loop
  252.  
  253.     // Create Our OpenGL Window
  254.     if (!CreateGLWindow("Something equally exciting!",screenWidth,screenHeight))
  255.     {
  256.         return 0;                                   // Quit If Window Was Not Created
  257.     }
  258.  
  259.     while(!done)                                    // Loop That Runs While done=FALSE
  260.     {
  261.         if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))   // Is There A Message Waiting?
  262.         {
  263.             if (msg.message==WM_QUIT)               // Have We Received A Quit Message?
  264.             {
  265.                 done=true;                          // If So done=TRUE
  266.             }
  267.             else                                    // If Not, Deal With Window Messages
  268.             {
  269.                 TranslateMessage(&msg);             // Translate The Message
  270.                 DispatchMessage(&msg);              // Dispatch The Message
  271.             }
  272.         }
  273.         else                                        // If There Are No Messages
  274.         {
  275.             display();                  // Draw The Scene
  276.             SwapBuffers(hDC);               // Swap Buffers (Double Buffering)
  277.         }
  278.     }
  279.  
  280.     console.Close();
  281.  
  282.     // Shutdown
  283.     KillGLWindow();                                 // Kill The Window
  284.     return (int)(msg.wParam);                       // Exit The Program
  285. }
  286.  
  287. //WIN32 Processes function - useful for responding to user inputs or other events.
  288. LRESULT CALLBACK WndProc(   HWND    hWnd,           // Handle For This Window
  289.                             UINT    uMsg,           // Message For This Window
  290.                             WPARAM  wParam,         // Additional Message Information
  291.                             LPARAM  lParam)         // Additional Message Information
  292. {
  293.     switch (uMsg)                                   // Check For Windows Messages
  294.     {
  295.         case WM_CLOSE:                              // Did We Receive A Close Message?
  296.         {
  297.             PostQuitMessage(0);                     // Send A Quit Message
  298.             return 0;                               // Jump Back
  299.         }
  300.         case WM_SIZE:                               // Resize The OpenGL Window
  301.         {
  302.             reshape(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
  303.             return 0;                               // Jump Back
  304.         }
  305.         break;
  306.     }
  307.  
  308.     // Pass All Unhandled Messages To DefWindowProc
  309.     return DefWindowProc(hWnd,uMsg,wParam,lParam);
  310. }
  311.  
  312. void KillGLWindow()                             // Properly Kill The Window
  313. {
  314.     if (hRC)                                            // Do We Have A Rendering Context?
  315.     {
  316.         if (!wglMakeCurrent(NULL,NULL))                 // Are We Able To Release The DC And RC Contexts?
  317.         {
  318.             MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  319.         }
  320.  
  321.         if (!wglDeleteContext(hRC))                     // Are We Able To Delete The RC?
  322.         {
  323.             MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  324.         }
  325.         hRC=NULL;                                       // Set RC To NULL
  326.     }
  327.  
  328.     if (hDC && !ReleaseDC(hWnd,hDC))                    // Are We Able To Release The DC
  329.     {
  330.         MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  331.         hDC=NULL;                                       // Set DC To NULL
  332.     }
  333.  
  334.     if (hWnd && !DestroyWindow(hWnd))                   // Are We Able To Destroy The Window?
  335.     {
  336.         MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  337.         hWnd=NULL;                                      // Set hWnd To NULL
  338.     }
  339.  
  340.     if (!UnregisterClass("OpenGL",hInstance))           // Are We Able To Unregister Class
  341.     {
  342.         MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  343.         hInstance=NULL;                                 // Set hInstance To NULL
  344.     }
  345. }
  346.  
  347. /*  This Code Creates Our OpenGL Window.  Parameters Are:                   *
  348.  *  title           - Title To Appear At The Top Of The Window              *
  349.  *  width           - Width Of The GL Window Or Fullscreen Mode             *
  350.  *  height          - Height Of The GL Window Or Fullscreen Mode            */
  351.  
  352. bool CreateGLWindow(char* title, int width, int height)
  353. {
  354.     GLuint      PixelFormat;            // Holds The Results After Searching For A Match
  355.     WNDCLASS    wc;                     // Windows Class Structure
  356.     DWORD       dwExStyle;              // Window Extended Style
  357.     DWORD       dwStyle;                // Window Style
  358.     RECT        WindowRect;             // Grabs Rectangle Upper Left / Lower Right Values
  359.     WindowRect.left=(long)0;            // Set Left Value To 0
  360.     WindowRect.right=(long)width;       // Set Right Value To Requested Width
  361.     WindowRect.top=(long)0;             // Set Top Value To 0
  362.     WindowRect.bottom=(long)height;     // Set Bottom Value To Requested Height
  363.  
  364.     hInstance           = GetModuleHandle(NULL);                // Grab An Instance For Our Window
  365.     wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw On Size, And Own DC For Window.
  366.     wc.lpfnWndProc      = (WNDPROC) WndProc;                    // WndProc Handles Messages
  367.     wc.cbClsExtra       = 0;                                    // No Extra Window Data
  368.     wc.cbWndExtra       = 0;                                    // No Extra Window Data
  369.     wc.hInstance        = hInstance;                            // Set The Instance
  370.     wc.hIcon            = LoadIcon(NULL, IDI_WINLOGO);          // Load The Default Icon
  371.     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);          // Load The Arrow Pointer
  372.     wc.hbrBackground    = NULL;                                 // No Background Required For GL
  373.     wc.lpszMenuName     = NULL;                                 // We Don't Want A Menu
  374.     wc.lpszClassName    = "OpenGL";                             // Set The Class Name
  375.  
  376.     if (!RegisterClass(&wc))                                    // Attempt To Register The Window Class
  377.     {
  378.         MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  379.         return false;                                           // Return FALSE
  380.     }
  381.    
  382.     dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window Extended Style
  383.     dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows Style
  384.    
  385.     AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust Window To True Requested Size
  386.  
  387.     // Create The Window
  388.     if (!(hWnd=CreateWindowEx(  dwExStyle,                          // Extended Style For The Window
  389.                                 "OpenGL",                           // Class Name
  390.                                 title,                              // Window Title
  391.                                 dwStyle |                           // Defined Window Style
  392.                                 WS_CLIPSIBLINGS |                   // Required Window Style
  393.                                 WS_CLIPCHILDREN,                    // Required Window Style
  394.                                 0, 0,                               // Window Position
  395.                                 WindowRect.right-WindowRect.left,   // Calculate Window Width
  396.                                 WindowRect.bottom-WindowRect.top,   // Calculate Window Height
  397.                                 NULL,                               // No Parent Window
  398.                                 NULL,                               // No Menu
  399.                                 hInstance,                          // Instance
  400.                                 NULL)))                             // Dont Pass Anything To WM_CREATE
  401.     {
  402.         KillGLWindow();                             // Reset The Display
  403.         MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  404.         return false;                               // Return FALSE
  405.     }
  406.  
  407.     static  PIXELFORMATDESCRIPTOR pfd=              // pfd Tells Windows How We Want Things To Be
  408.     {
  409.         sizeof(PIXELFORMATDESCRIPTOR),              // Size Of This Pixel Format Descriptor
  410.         1,                                          // Version Number
  411.         PFD_DRAW_TO_WINDOW |                        // Format Must Support Window
  412.         PFD_SUPPORT_OPENGL |                        // Format Must Support OpenGL
  413.         PFD_DOUBLEBUFFER,                           // Must Support Double Buffering
  414.         PFD_TYPE_RGBA,                              // Request An RGBA Format
  415.         24,                                         // Select Our Color Depth
  416.         0, 0, 0, 0, 0, 0,                           // Color Bits Ignored
  417.         0,                                          // No Alpha Buffer
  418.         0,                                          // Shift Bit Ignored
  419.         0,                                          // No Accumulation Buffer
  420.         0, 0, 0, 0,                                 // Accumulation Bits Ignored
  421.         24,                                         // 24Bit Z-Buffer (Depth Buffer)  
  422.         0,                                          // No Stencil Buffer
  423.         0,                                          // No Auxiliary Buffer
  424.         PFD_MAIN_PLANE,                             // Main Drawing Layer
  425.         0,                                          // Reserved
  426.         0, 0, 0                                     // Layer Masks Ignored
  427.     };
  428.    
  429.     if (!(hDC=GetDC(hWnd)))                         // Did We Get A Device Context?
  430.     {
  431.         KillGLWindow();                             // Reset The Display
  432.         MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  433.         return false;                               // Return FALSE
  434.     }
  435.  
  436.     if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
  437.     {
  438.         KillGLWindow();                             // Reset The Display
  439.         MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  440.         return false;                               // Return FALSE
  441.     }
  442.  
  443.     if(!SetPixelFormat(hDC,PixelFormat,&pfd))       // Are We Able To Set The Pixel Format?
  444.     {
  445.         KillGLWindow();                             // Reset The Display
  446.         MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  447.         return false;                               // Return FALSE
  448.     }
  449.  
  450.     HGLRC tempContext = wglCreateContext(hDC);
  451.     wglMakeCurrent(hDC, tempContext);
  452.    
  453.     GLenum err = glewInit();
  454.     if (GLEW_OK != err)
  455.     {
  456.         cout << " GLEW ERROR" << endl;
  457.     }
  458.    
  459.     int attribs[] =
  460.     {
  461.         WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
  462.         WGL_CONTEXT_MINOR_VERSION_ARB, 2,
  463.         WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
  464.         0
  465.     };
  466.    
  467.     if(wglewIsSupported("WGL_ARB_create_context") == 1)
  468.     {
  469.         hRC = wglCreateContextAttribsARB(hDC,0, attribs);
  470.         wglMakeCurrent(NULL,NULL);
  471.         wglDeleteContext(tempContext);
  472.         wglMakeCurrent(hDC, hRC);
  473.     }
  474.     else
  475.     {   //It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before)
  476.         hRC = tempContext;
  477.         cout << " not possible to make context "<< endl;
  478.     }
  479.  
  480.     //Checking GL version
  481.     const GLubyte *GLVersionString = glGetString(GL_VERSION);
  482.  
  483.     cout << "OpenGL version is: " << GLVersionString << endl;
  484.  
  485.     //Which version are we using?
  486.     int OpenGLVersion[2];
  487.     glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0]);
  488.     glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1]);
  489.  
  490.     cout << "OpenGL version is : "<< OpenGLVersion[0] << " " << OpenGLVersion[1] << endl;
  491.  
  492.     ShowWindow(hWnd,SW_SHOW);                       // Show The Window
  493.     SetForegroundWindow(hWnd);                      // Slightly Higher Priority
  494.     SetFocus(hWnd);                                 // Sets Keyboard Focus To The Window
  495.    
  496.     init();
  497.  
  498.     reshape(width, height);                         // Set Up Our Perspective GL Screen
  499.    
  500.    
  501.     return true;                                    // Success
  502. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement