Resource Leak opengl/win32 - c++

Hello I've recently started learning win32/opengl and I managed to write a function that displays a multi colored cube within a window. My problem is there is a resource leak but I'm stumped and not sure what exactly I'm forgetting to delete.
NOTE I have narrowed it down to be within this function
void display()
{
g.hglrc = wglCreateContext(g.hdc);
wglMakeCurrent(g.hdc, g.hglrc);
// make the color a white hue
glClearColor(1.0F, 1.0F, 1.0F, 1.0F);
// Clear screen and Z-buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Rotate when user changes rotate_x and rotate_y
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
//Multi-colored side - FRONT
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0); glVertex3f(0.5, -0.5, -0.5); // P1 is red
glColor3f(0.0, 1.0, 0.0); glVertex3f(0.5, 0.5, -0.5); // P2 is green
glColor3f(0.0, 0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5); // P3 is blue
glColor3f(1.0, 0.0, 1.0); glVertex3f(-0.5, -0.5, -0.5); // P4 is purple
glEnd();
// White side - BACK
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glEnd();
// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glEnd();
// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glEnd();
// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
wglMakeCurrent(NULL, NULL);
SwapBuffers(g.hdc);
ReleaseDC(g.hwnd, g.hdc);
wglDeleteContext(g.hglrc);
}

g.hglrc = wglCreateContext(g.hdc);
Don't do that.
You don't create a rendering context every time you need to redraw the screen. You create it once; it should only go away when your window goes away.
Now, that doesn't necessarily justify why creating and destroying a rendering context would leave resources lying around. But that's irrelevant; you shouldn't do it because of performance. Rendering context creation and destruction is not a fast process, nor is it intended to be.

Related

OpenGL displaying a square instead of a cube

I am starting to use tinker with OpenGL and I want to draw a cube. I went to a tutorial, followed that, and only got this weird square.
Here's my code.
#include <GLFW/glfw3.h>
void drawCube() {
float rotate_x{ 193 };
float rotate_y{ 112 };
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0); glVertex3f(0.5, -0.5, -0.5);
glColor3f(0.0, 1.0, 0.0); glVertex3f(0.5, 0.5, -0.5);
glColor3f(0.0, 0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5);
glColor3f(1.0, 0.0, 1.0); glVertex3f(-0.5, -0.5, -0.5);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -0.5);
glLoadIdentity();
glRotatef(30, 0.0, 1.0, 0.0);
glEnd();
}
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Triangle", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
drawCube();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
I'm using GLFW to do this, and I'm building it in Visual Studio 2017 Community Edition.
I also tried to rotate it at the end of drawCube().
The tutorial I followed was https://www.wikihow.com/Make-a-Cube-in-OpenGL but I tweaked it a bit to use glfw.
You are drawing a single polygon with 24 vertices. Since OpenGL requires the polygon to be concave and planar (which your data isn't) it draws some random stuff.
If you want to draw a cube, you either have to split the drawing the call glBegin(GL_POLYGON) and glEnd() for each face separately (as the tutorial shows in the second code sample in section 4), or you can change the primitive mode to GL_QUADS.
Note, that the OpenGL version you are using (fixed function pipeline) is outdated for more than 10 years now. You might want to consider switching to (at least) OpenGL 3.3 core profile and use shader.
Camera
I do not see you are setting the matrices anywhere... So my bet is that your matrices are unit resulting in 2D view no matter how you tweak the rendered axis aligned data.
Use gluPerspective for the GL_PROJECTION. Its a bit tricky to set up the perspective 3D view properly for rookies (as it views in -Z direction which is exact opposite than identity matrix) so your mesh is in viewable area.
CULL_FACE
for starters try glDisable(GL_CULL_FACE) as your data will most likely contain winding errors and you will not know what faces you already have or not otherwise.
cube mesh
right now you are hardcoding it using glVertex calls its much easier to use separate arrays for points and faces (QUADS or TRIANGLES). Also as BDL pointed out you are using forbidden commands inside glBegin/glEnd calls they are ignored and slows things down due to error handling.
lighting
to feel the 3D better you should also add normals for each face and enable lights. Otherwise you would need to color each face with different color to see the "3D".
Take a look at my:
complete GL+GLSL+VAO/VBO C++ example
just ignore the advanced stuff (GLSL,VAO/VBO...) and look for view settings and the cube mesh data. You just need to render it with for loop instead of VAO/VBO. Here example:
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
#ifndef vao_indices
glBegin(GL_QUADS);
for (int i=0;i<6*4*3;i+=3)
{
glNormal3fv(vao_nor+i);
glColor3fv (vao_col+i);
glVertex3fv(vao_pos+i);
}
glEnd();
#else
int i,j,k;
const GLfloat vao_nor[]=
{
// nx ny nz
0.0, 0.0,-1.0,
0.0, 0.0,+1.0,
0.0,-1.0, 0.0,
+1.0, 0.0, 0.0,
0.0,+1.0, 0.0,
-1.0, 0.0, 0.0,
};
glBegin(GL_QUADS);
for (j=0;j<6*4;j++)
{
i=vao_ix[j]; i+=i+i;
k=j>>2; k+=k+k;
glNormal3fv(vao_nor+k);
glColor3fv (vao_col+i);
glVertex3fv(vao_pos+i);
}
glEnd();
#endif
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
using the mesh from gl_simple in that linked QA in both modes (indices and direct).

OpenGL custom quads have lighting bugs

I'm trying to figure out how to write my own primitives like gluSolidCube()..
In the following code I'm drawing 2 quads. One with the help of this method (the red one) and another one - by my own with the help of glBegin()/glEnd() (the blue one).
glPushMatrix();
glRotatef(-angleX, 0, 0, 1);
glRotatef(angleY, 0, 1, 0);
glColor3f(1, 0, 0);
glTranslatef(0.6, 0, 0);
glutSolidCube(1);
glColor3f(0, 0, 1);
glTranslatef(-1.2, 0, 0);
glPolygonMode(GL_FRONT, GL_FILL);
glShadeModel(GL_SMOOTH);
glBegin(GL_QUADS);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glVertex3f(-0.5, -0.5, 0.5);
glEnd();
glPopMatrix();
So as you can see at the following screenshots the lightnings on the red quad is correct unlike the blue one. How to solve this?
OpenGL fixed-function lighting won't work correctly without sensible vertex/face normals.
You need to supply some, perhaps via glNormal().

How do I make an open cube (missing one surface) without getting effect where sides are mirrored or switched in OpenGL?

I am trying to create a cube that has one surface missing (an open box in effect), but when I make it, the side opposite to the missing side gets super imposed on where the opening should be when the object is rotated.
Here is what I mean:
View of Front and back of Cube angled:
How do I get rid of the weird color overrides going on?
Here is my current code:
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <stdlib.h>
#include <GL/glut.h>
void display();
void viewButtons();
double rotationY = 0;
double rotationX = 0;
void display()
{
//Clear the screen and clear z-buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Rotate when user changes rotate_x and rotate_y
glRotatef(rotationX, 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
//Vertices and colors
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, -0.5); // P1 is red
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.5, 0.5, -0.5); // P2 is green
glColor3f(0.0, 0.0, 1.0);
glVertex3f(-0.5, 0.5, -0.5); // P3 is blue
glColor3f(1.0, 0.0, 1.0);
glVertex3f(-0.5, -0.5, -0.5); // P4 is purple
glEnd();
/*// White side - BACK
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glEnd();*/
// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glEnd();
// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glEnd();
// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
glFlush();
glutSwapBuffers();
}
void viewButtons(int button, int x, int y)
{
if (button == GLUT_KEY_RIGHT)
rotationY += 5;
else if (button == GLUT_KEY_LEFT)
rotationY -= 5;
else if (button == GLUT_KEY_UP)
rotationX += 5;
else if (button == GLUT_KEY_DOWN)
rotationX -= 5;
//update display
glutPostRedisplay();
}
int main(int argc, char **argv) {
// init GLUT and create window
// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(720, 640);
glutCreateWindow("Room with objects");
// register callbacks
glutDisplayFunc(display);
glutSpecialFunc(viewButtons);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}
You need to enable the depth test. Put this somewhere, in initialization, in your program:
glEnable(GL_DEPTH_TEST);

Using glut, how do I make it so I can move an object around in a scene by clicking and dragging it around?

I have written a program that creates a room that currently contains a triangle. I want to make more objects like this triangle, but I also want to add functionality that allows me to move the objects by clicking on them and dragging them. I am thinking the best way would be to create some sort of template/prototype etc. etc. that has the geometric data passed via a constructor but has a function for moving it around by mouse, but I am unsure if I have it right, and I am not entirely sure about what I actually need to do to get this working like that. Here is my current code, it allows rotation of scene using direction keys, but I am unsure how to make it so I can click on an object and drag it at this point (I have the beginnings of something I was trying for this commented out because I don't think it would work, but if it will let me know how):
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <stdlib.h>
#include <GL/glut.h>
void display();
void viewButtons();
//const double ZoomSTEP = 0.2;
//const double zoomFactor = 1.03;
double rotationY = 0;
double rotationX = 0;
// Mouse positions, normalized to [0,1].
//double xMouse = 0.5;
//double yMouse = 0.5;
//GLdouble startView = 2.0;
void display()
{
//Clear the screen and clear z-buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Rotate when user changes rotate_x and rotate_y
glRotatef(rotationX, 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
glBegin(GL_POLYGON);
//Vertices and colors
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, 0.5); // P1 is red
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.5, 0.5, 0.5); // P2 is green
glColor3f(0.0, 0.0, 1.0);
glVertex3f(-0.5, 0.5, 0.5); // P3 is blue
glColor3f(1.0, 0.0, 1.0);
glVertex3f(-0.5, -0.5, 0.5); // P4 is purple
glEnd();
/*// White side - BACK
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glEnd();*/
// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 1.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, -0.5, 0.5);
glEnd();
// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, 0.5);
glEnd();
// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -0.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.5, 0.6, 0.3);
glVertex3f(0.3, 0.1, 0.5);
glVertex3f(0.4, 0.1, 0.5);
glVertex3f(0.2, -0.2, 0.1);
glEnd();
glFlush();
glutSwapBuffers();
}
void viewButtons(int button, int x, int y)
{
if (button == GLUT_KEY_RIGHT)
rotationY += 5;
else if (button == GLUT_KEY_LEFT)
rotationY -= 5;
else if (button == GLUT_KEY_UP)
rotationX += 5;
else if (button == GLUT_KEY_DOWN)
rotationX -= 5;
//update display
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(720, 640);
glutCreateWindow("Room with objects");
// register callbacks
glutDisplayFunc(display);
glutSpecialFunc(viewButtons);
glEnable(GL_DEPTH_TEST);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}
If you want to transpose/rotate/scale an arbitrary object the template for this is something like this:
save your current world matrix (you can do that using glPushMatrix)
translate you object to the position you want (using glRotate/glTranslate/glScale)
draw you object (the glBegin/glEnd part)
retrieve your old matrix (if you pushed it to the stack use glPopMatrix)
Repeat this process for every drawable object in your scene.
When manipulating objects you might define one matrix for each object so that you can manipulate them independently. You would then compute the matrices for each object yourself (have a look into glm - a neat framework for doing exactly such things) and then instead of step 2. use glMultMatrix and set you own matrix.
Also, you are using legacy openGL code, so I'am guessing you are learning right now how things work out. My suggestion is instead of learning the old stuff: Have a look into glsl shader programming, vertexbufferobjects and all the good stuff that is beyond opengl 1.4 there are some really good tuts out there http://www.opengl-tutorial.org/

Get camera inside my skybox

So I am working on a homework assignment and I have managed to create my skybox and it looks correct, the only problem is that my camera is outside the skybox.
I tried the command gluLookAt thinking maybe that would focus me into the box, but it didn't work. Here's the code that I have now. If anyone could let me know what I'm doing wrong it would be greatly appreciated:
gluLookAt(
0,0,0,
0,0,0
0,1,0);
glPushMatrix();
//load identity matrix
glLoadIdentity();
//update x, y and z rotation directions
glRotatef(currentRotation[1], 1.0, 0.0, 0.0); //x rotation
glRotatef(currentRotation[2], 0.0, 1.0, 0.0); //y rotation
glRotatef(currentRotation[3], 0.0, 0.0, 1.0); //z rotation
/*
//update scale of display
glScalef(currentScaling[1],
currentScaling[2],
currentScaling[3]);*/
//translate the image
glTranslatef(currentTranslation[1],
currentTranslation[2],
currentTranslation[3]);
/* Clear buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D); // Enable texturing from now on
//front quadrant
glBindTexture(GL_TEXTURE_2D,frontTextureId); // select which texture to use
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(1.0 ,0.0); glVertex3f(-0.5, 0.5, 0.5);
glTexCoord2f(0.0 ,0.0); glVertex3f(0.5, 0.5, 0.5);
glTexCoord2f(0.0 ,1.0); glVertex3f(0.5, 0.5, -0.5);
glTexCoord2f(1.0 ,1.0); glVertex3f(-0.5, 0.5, -0.5);
glEnd();
//left quadrant
glBindTexture(GL_TEXTURE_2D, leftTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5);
glTexCoord2f(1.0, 1.0); glVertex3f(-0.5, -0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, -0.5, 0.5);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, 0.5, 0.5);
glEnd();
//back quadrant
glBindTexture(GL_TEXTURE_2D, backTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, -0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, 0.5);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, -0.5, -0.5);
glEnd();
//right quadrant
glBindTexture(GL_TEXTURE_2D, rightTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, 0.5, 0.5);
glTexCoord2f(0.0, 0.0); glVertex3f(0.5, -0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, -0.5);
glEnd();
//up quadrant
glBindTexture(GL_TEXTURE_2D, upTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, 0.5, 0.5);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, 0.5);
glEnd();
//down quadrant
glBindTexture(GL_TEXTURE_2D, downTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, -0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, -0.5);
glEnd();
Thank you for any help you can provide!
I think your problem is in the glulookat
try with this values
gluLookAt(0.0, 0.0 , 2.0 ,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
Few problems at a glance: gluLookAt arguments: first three are camera position, next three are camera target - should not be the same, camera must have valid direction vector. Next, your skybox is only 1.0 unit size - make it bigger. Use a constant instead of 0.5 everywhere, that way you can control it in one place.
Well you do have a glTranslate() call in there, so unless you're passing it zeros, that's probably why you're not in the box.