Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ OpenGL Cube not showing up on screen
    text
    copied!<p>Hey this is my first post on stackflow so bare with me. i have been attempting to use OpenGL with C++ lately and i have come a cross a problem when trying to render a cube with lighting...but it doesn't appear i believe this is due to some kinda of clipping error but i have no clue :( any help would be appreciated.</p> <p>here is my code...</p> <p>the initialization function... </p> <pre><code>glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); //Enable lighting glEnable(GL_LIGHT0); //Enable light #0 glEnable(GL_LIGHT1); //Enable light #1 glEnable(GL_NORMALIZE); //Automatically normalize normals </code></pre> <p>and here is the draw code</p> <pre><code> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glTranslatef(0.0f, 0.0f, -8.0f); //Add ambient light GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //Color (0.2, 0.2, 0.2) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add positioned light GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5) GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); //Add directed light GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2) //Coming from the direction (-1, 0.5, 0.5) GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); glRotatef(Rotation, 0.0f, 1.0f, 0.0f); glColor3f(1.0f, 1.0f, 0.0f); glBegin(GL_QUADS); //Front glNormal3f(0.0f, 0.0f, 1.0f); //glNormal3f(-1.0f, 0.0f, 1.0f); glVertex3f(-1.5f, -1.0f, 1.5f); //glNormal3f(1.0f, 0.0f, 1.0f); glVertex3f(1.5f, -1.0f, 1.5f); //glNormal3f(1.0f, 0.0f, 1.0f); glVertex3f(1.5f, 1.0f, 1.5f); //glNormal3f(-1.0f, 0.0f, 1.0f); glVertex3f(-1.5f, 1.0f, 1.5f); //Right glNormal3f(1.0f, 0.0f, 0.0f); //glNormal3f(1.0f, 0.0f, -1.0f); glVertex3f(1.5f, -1.0f, -1.5f); //glNormal3f(1.0f, 0.0f, -1.0f); glVertex3f(1.5f, 1.0f, -1.5f); //glNormal3f(1.0f, 0.0f, 1.0f); glVertex3f(1.5f, 1.0f, 1.5f); //glNormal3f(1.0f, 0.0f, 1.0f); glVertex3f(1.5f, -1.0f, 1.5f); //Back glNormal3f(0.0f, 0.0f, -1.0f); //glNormal3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.5f, -1.0f, -1.5f); //glNormal3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.5f, 1.0f, -1.5f); //glNormal3f(1.0f, 0.0f, -1.0f); glVertex3f(1.5f, 1.0f, -1.5f); //glNormal3f(1.0f, 0.0f, -1.0f); glVertex3f(1.5f, -1.0f, -1.5f); //Left glNormal3f(-1.0f, 0.0f, 0.0f); //glNormal3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.5f, -1.0f, -1.5f); //glNormal3f(-1.0f, 0.0f, 1.0f); glVertex3f(-1.5f, -1.0f, 1.5f); //glNormal3f(-1.0f, 0.0f, 1.0f); glVertex3f(-1.5f, 1.0f, 1.5f); //glNormal3f(-1.0f, 0.0f, -1.0f); glVertex3f(-1.5f, 1.0f, -1.5f); glEnd(); SwapBuffers(hDC); Sleep (1); </code></pre> <p>any help will be appreciated </p> <p><strong>Edit one</strong><br> after following the advice of Keith i attempted to use the gluLookAt like this...</p> <pre><code>void gluLookAt ( 10.0 , 10.0 , 10.0 , 1.5, -1.0, 1.5, 0.0, 0.0, 1.0 ); </code></pre> <p>but i get an error</p> <p>|74|error: variable or field `gluLookAt' declared void|</p> <p>Final edit<br> thanks for your help everyone...it turned out i fail :( i hadn't declared the translation...or the perceptive..along with other crucial components...but i got it all working :D and thanks to Keith i no how to control the camera</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload