Unhandled exception on openGL text display - c++

I am trying to draw text using openGL which will be displayed in a window, over a kinect camera image. The program can draw squares and other shapes fine, but when I call the method to draw the text, it crashes. It seems to be crashing on the
glutStrokeCharacter(font, c);
Everything else works and when I comment out just this line the program still runs fine. Below is a code snippet of how I try and draw the text.
void Button::DrawSquare(bool selected)
{
glEnable( GL_POINT_SMOOTH );
glLineWidth(7);
if (selected == true) glColor3f(0,1,0);
else glColor3f((123.0/255.0f),(205/255.0f),(237.0/255.0f));
glBegin(GL_LINE_LOOP);
glVertex2f(X, Y);
glVertex2f(X+length, Y);
glVertex2f(X+length, Y+width);
glVertex2f(X, Y+width);
glEnd();
glLineWidth(3);
glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
glVertex2f(X, Y);
glVertex2f(X+length, Y);
glVertex2f(X+length, Y+width);
glVertex2f(X, Y+width);
glEnd();
glLineWidth(4);
//Start drawing text
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
if (selected == true) glColor3f(0,1,0);
else glColor3f(1,1,0);
void *font = GLUT_BITMAP_TIMES_ROMAN_10;
glRasterPos2i(this->X+15,this->Y+35);
string s(*this->trackname);
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
char c = *i;
glutStrokeCharacter(font, c);// <<-- Line that gives error
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glColor3f(255,255,255);
}
The drawing of the squares just before the text works fine.

Here is a minimal working example of how to render text using glutBitmapCharacter:
static const std::string text_to_render = "testing 1 2 3 4";
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glDisable( GL_DEPTH_TEST ); // disable to render text in front of anything else
glRasterPos2f(0, 0); // center of screen
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GLvoid * font = GLUT_BITMAP_TIMES_ROMAN_10;
glColor3f(1.0f, 0.0f, 0.0f);
for(char chr : text_to_render)
{
glutBitmapCharacter(font, chr);
}
glEnable(GL_DEPTH_TEST); // re-enable depth test
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glutSwapBuffers();
}
The only difference here is that I'm disabling OpenGL's GL_DEPTH_TEST and I'm loading the identity matrices after pushing the current matrices.
Let me know if this is of any help.

Related

Opengl/Glut keyboard input trouble

i have an assignment to draw a pyramid onto the screen and then rotate after i press the 'k' key in my keyboard.
Everything works ok, except the rotation part as the program doesn't seem to be noting me pressing the key. The code goes as follows:
void changeSize(int w, int h) {
if(h == 0)
h = 1;
float ratio = w * 1.0 / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
// Set perspective
gluPerspective(45.0f ,ratio, 1.0f ,1000.0f);
// return to the model view matrix mode
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
// clear buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set the camera
glLoadIdentity();
gluLookAt(5.0,5.0,5.0,
0.0,0.0,0.0,
0.0f,2.0f,0.0f);
// put the geometric transformations here
// put drawing instructions here
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-100.0f, 0.0f, 0.0f);
glVertex3f( 100.0f, 0.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.0f, -100.0f, 0.0f);
glVertex3f(0.0f, 100.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, -100.0f);
glVertex3f(0.0f, 0.0f, 100.0f);
glEnd();
//triangulos da base
glBegin(GL_TRIANGLES);
glColor3f(255.0f,255.0f,255.0f);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(-1.0f,0.0f,-1.0f);
glVertex3f(-1.0f,0.0f,1.0f);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,-1.0f);
glVertex3f(-1.0f,0.0f,-1.0f);
glEnd();
//triangulos das faces
glBegin(GL_TRIANGLES);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glVertex3f(-1.0f,0.0f,1.0f);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f(1.0f,0.0f,-1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glVertex3f(1.0f,0.0f,1.0f);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f(1.0f,0.0f,-1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glVertex3f(-1.0f,0.0f,-1.0f);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,0.0f,-1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glVertex3f(-1.0f,0.0f,1.0f);
glEnd();
// End of frame
glutSwapBuffers();
}
// write function to process keyboard events
void rotate (unsigned char key, int x, int y) {
if (key == 'k')
glRotatef(45,1.0,1.0,0.0);
glutPostRedisplay();
}
int main(int argc, char **argv) {
// init GLUT and the window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(1200,1200);
glutCreateWindow("CG#DI-UM");
// Required callback registry
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
// put here the registration of the keyboard callbacks
glutKeyboardFunc(rotate);
// OpenGL settings
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
// enter GLUT's main cycle
glutMainLoop();
return 0;
}
It seems that my program is not noting me pressing the key even tho i am. Im tried only printing the keys that are being pressed, and that works, so i'm really lost here.
glRotatef seem to have no effect in rotate, because glLoadIdentity() is called at the begin of renderScene. Actually glRotatef changes the current matrix, but when the scene is rendered (renderScene), then glLoadIdentity() loads the Identity matrix to the current matrix.
Anyway it is a bad style to do changes to the current matrix in input event callbacks. Change states and values of variables in the input events and use the variables to set the current model view matrix before the scene is rendered in renderScene.
Add a global variable angle:
float angle = 0.0f;
Change the value of the variable in renderScene. e.g:
void rotate (unsigned char key, int x, int y) {
if (key == 'k') {
angle += 45.0f;
glutPostRedisplay();
}
}
And apply the rotation to the current matrix in renderScene:
void renderScene(void) {
// clear buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set the camera
glLoadIdentity();
gluLookAt(5.0,5.0,5.0,
0.0,0.0,0.0,
0.0f,2.0f,0.0f);
// apply rotation
glRotatef(angle, 1.0f, 1.0f, 0.0f);
// [...]
}

How to make the background of my texture transparent? (My image is already backgroundless)

I have a backgroundless image of a gun. I am trying to build a first person shooter game with the help of this 2D image of a gun. I have loaded the texture in my program but I am unable to make the background of the gun transparent. Moreover, why should I even have to do that when my image is already backgroundless. I used clippingmagic.com to remove the background of my image. The code is:
#include <iostream>
#include <stdlib.h> //Needed for "exit" function
#include<SOIL/SOIL.h>
//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
using namespace std;
const float A = 1366.0; //width of the computer screen
const float B = 768.0; //height of the computer screen
//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
int x, int y) { //The current mouse coordinates
switch (key) {
case 27: //Escape key
exit(0); //Exit the program
}
}
//Initializes 3D rendering
void initRendering() {
//Makes 3D drawing work when something is in front of something else
glEnable(GL_DEPTH_TEST);
}
//Called when the window is resized
void handleResize(int w, int h) {
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
//Set the camera perspective
glLoadIdentity(); //Reset the camera
gluPerspective(45.0, //The camera angle
(double)w / (double)h, //The width-to-height ratio
1.0, //The near z clipping coordinate
200.0); //The far z clipping coordinate
}
//Draws the 3D scene
void drawScene() {
//Clear information from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glTranslatef(0.0,0.0,-10.0);
//DRAW WALL OF ROOM
glBegin(GL_QUADS);
glColor3f(0.0, 1.0, 1.0);
glVertex3f(-100.0, -100.0, -100.0);
glVertex3f(-100.0, 100.0, -100.0);
glVertex3f( 100.0, 100.0, -100.0);
glVertex3f( 100.0, -100.0, -100.0);
glEnd();
//DRAW GUN
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLuint gun_tex_id = SOIL_load_OGL_texture
(
"GUN.png",
SOIL_LOAD_RGB, //I even tried SOIL_LOAD_AUTO and SOIL_LOAD_RGBA but it didn't help
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_MULTIPLY_ALPHA
);
glBindTexture(GL_TEXTURE_2D, gun_tex_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTranslatef(2.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-4.1,-4.15, 0.0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 3.0,-4.15, 0.0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 3.0, 1.2, 0.0);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-4.1, 1.2, 0.0);
glEnd();
glDisable(GL_BLEND);
glutSwapBuffers(); //Send the 3D scene to the screen
}
void myinit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); /* gray background */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( -A/2, A/2, -B/2, B/2, -200, 200);
/* In World coordinates:position the "clipping rectangle" at -A/2, its right edge at +A/2, its bottom edge at -B/2 and its top edge at +B/2 */
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(A, B); //Set the window size
//Create the window
glutCreateWindow("My shooting game");
initRendering(); //Initialize rendering
//Set handler functions for drawing, keypresses, and window resizes
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
myinit();
glutMainLoop(); //Start the main loop. glutMainLoop doesn't return.
return 0; //This line is never reached
}
You can do it using glBlendFunc function.
Try adding the following code snippet before you bind texture to the object.
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Read this for more information.

Displaying fixed location 2D text in a 3D OpenGL world using GLUT

I have an OpenGL project which uses GLUT (not freeglut) wherein I would like to display 2D text on the viewport at a fixed location. The rest of my objects are in 3D world co-ordinates.
This answer to a related old question says that,
the bitmap fonts which ship with GLUT are simple 2D fonts and are not suitable for display inside your 3D environment. However, they're perfect for text that needs to be overlayed on the display window.
I've tried the approach outlined in the accepted answer, but it does not give me the desired output. Following is a code snippet of the display function:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, -(dis+ddis)); //Translate the camera
glRotated(elev+delev, 1.0, 0.0, 0.0); //Rotate the camera
glRotated(azim+dazim, 0.0, 1.0, 0.0); //Rotate the camera
.
.
.
draw 3D scene
.
.
.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, win_width, 0.0, win_height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glRasterPos2i(10, 10);
string s = "Some text";
void * font = GLUT_BITMAP_9_BY_15;
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
char c = *i;
glColor3d(1.0, 0.0, 0.0);
glutBitmapCharacter(font, c);
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
glSwapBuffers();
}
A similar question to what I want seems to have been asked, but has no accepted answers by the author.
Answers in general seem to suggest using other libraries (mostly OS specific) to achieve the overlay. However, there is no clear indication to whether this can be achieved with GLUT alone. Can it be done?
I ran into this same problem using glut to create a model of the solar system. Here's how I solved it: (using your code from above)
glDisable(GL_TEXTURE_2D); //added this
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, win_width, 0.0, win_height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glRasterPos2i(10, 10);
string s = "Some text";
void * font = GLUT_BITMAP_9_BY_15;
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
char c = *i;
glColor3d(1.0, 0.0, 0.0);
glutBitmapCharacter(font, c);
}
glMatrixMode(GL_PROJECTION); //swapped this with...
glPopMatrix();
glMatrixMode(GL_MODELVIEW); //...this
glPopMatrix();
//added this
glEnable(GL_TEXTURE_2D);
You'll note i switched glMatrixMode(GL_PROJECTION); and glMatrixMode(GL_MODELVIEW); near the end. I decided to do this because of this website. I also has to surround the code section with glDisable(GL_TEXTURE_2D) and glEnable(GL_TEXTURE_2D).
Hope that helps- I worked for me. My solar system uses classes to perform all of this, I'd be happy to share more details upon request.
As I said, the code you posted works perfectly fine. Here's the code I used to test it:
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include "GL/glu.h"
//glm not required
//#include <glm.hpp>
//#include <gtc/matrix_transform.hpp>
#include <string>
int win_width = 500, win_height = 500;
void renderScene(void) {
static float dis=0, ddis=0, elev=0, delev=0, azim=0, dazim=0;
azim += 0.5f;
if (azim >= 360.0f){
azim -= 360.0f;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -(dis + ddis));
glRotated(elev + delev, 1.0, 0.0, 0.0);
glRotated(azim + dazim, 0.0, 1.0, 0.0);
glScalef(2.0f,2.0f,2.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glEnd();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//I like to use glm because glu is deprecated
//glm::mat4 orth= glm::ortho(0.0f, (float)win_width, 0.0f, (float)win_height);
//glMultMatrixf(&(orth[0][0]));
gluOrtho2D(0.0, win_width, 0.0, win_height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(1.0f, 0.0f, 0.0f);//needs to be called before RasterPos
glRasterPos2i(10, 10);
std::string s = "Some text";
void * font = GLUT_BITMAP_9_BY_15;
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
{
char c = *i;
//this does nothing, color is fixed for Bitmaps when calling glRasterPos
//glColor3f(1.0, 0.0, 1.0);
glutBitmapCharacter(font, c);
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glEnable(GL_TEXTURE_2D);
glutSwapBuffers();
glutPostRedisplay();
}
int main(int argc, char **argv) {
// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(win_width, win_height);
glutCreateWindow("GLUT Test");
// register callbacks
glutDisplayFunc(renderScene);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}
The usual disclaimers about deprecated fixed function pipeline and others apply.
There is a tricky way to solve your problem.
Please write a code before you call a function or what ever it is as written below:
glutBitmaCharacter(font, ' ');//
Does it....! And it should work...

openGL rendering glulookat

I rendered a triangle in the scene but now that I'm adding mouse navigation nothing seems to work anymore. So I deleted all the navigation stuff again to see what was wrong with my use of gluLookAt(). But even in a very simple case I dont see anything:
void GLScene::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//m_navigation.UpdateCamera();
gluLookAt(0 ,0 ,20,
0,0,-1,
0, -1, 0 );
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(0,100,0);
glVertex3f(100,0,0);
glEnd();
}
you messed up your object transformation matrices
correct code (untested)
void GLScene::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0 ,0 ,20,
0,0,-1,
0, -1, 0 );
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(0,100,0);
glVertex3f(100,0,0);
glEnd();
}

OpenGL Drawing Axis in Corner

I've been searching on how to draw an Indicator-Axis in my OpenGL scene. The project's nested in a Qt OpenGL widget, but I think the problem is independent of Qt.
I have found on here and forums from years ago that suggest storing the viewport and data, loading new ones for the botttom corner, apply my rotations and draw, then restore the matrices. This seems the most beneficial to me, but I'm guessing I'm still missing some critical info in my OpenGL knowledge.
For now I just have it drawing a red line from -x to x, so I expected to have a red square in the bottom left of the screen:
void GLWidget::drawAxis()
{
float tempPro[16];
float tempMod[16];
glGetFloatv(GL_PROJECTION_MATRIX, &tempPro[0]);
glGetFloatv(GL_MODELVIEW_MATRIX, &tempMod[0]);
glViewport(0, 0, 50, 50);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, 1.0f, 0.1f, 20.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glEnable( GL_LINE_SMOOTH );
glLineWidth( 1.5 );
glVertex3f(-1000, 0, 0);
glVertex3f(1000, 0, 0);
glEnd();
glPopMatrix();
glViewport(0, 0, 960, 600);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(tempPro);
gluPerspective(45.0f, (960.0/600.0), 0.1f, 400.0f);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(tempMod);
}
Instead I get nothing, just a large empty scene, and I'm unsure how to proceed. My paintGL is essentially:
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Camera.Render();
glTranslatef(0.0, 0.0, 0.0);
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(50.0f, 0.0f, 50.0f);
glVertex3f(50.0f, 0.0f, -50.0f);
glVertex3f(-50.0f, 0.0f, -50.0f);
glVertex3f(-50.0f, 0.0f, 50.0f);
glEnd();
drawAxis();
}
Not calling the draw-axis function still gives me my plane, with it, I get a large blank scene. Am I missing something in how I'm implementing the drawAxis? Should I setup another camera for the function or something like that?
You can use glPushMatrix() and glPopMatrix() to save and restore the state of your Projection and ModelView matrices.
Your not setting up your ModelView matrix to anything useful.
Try something like this:
void GLWidget::drawAxis()
{
glViewport(0, 0, 50, 50);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
gluPerspective(45.0f, 1.0f, 0.1f, 20.0f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//This really has to come from your camera....
gluLookAt(10.0f,10.0f,10.0f, 0.0f,0.0f,0.0f, 0.0f,0.1f,0.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glEnable( GL_LINE_SMOOTH );
glLineWidth( 1.5 );
glBegin(GL_LINES);
glVertex3f(-1000, 0, 0);
glVertex3f(1000, 0, 0);
glEnd();
//Restore View
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glViewport(0, 0, 960, 600);
}