PDA

View Full Version : issue with "camera" settings



coffeeaddict
05-27-2011, 09:07 AM
I am trying to render a triangle that is stored in vertex arrays. All of this works fine as long as I do not translate the mesh more than 1.0 or less than -1.0 on the z-axis. If I translate it more or less then that then nothing is rendered on the screen. I'm guessing that the camera is clipping it because it is too far away but I do not know how to resolve that.

As you have probably ascertained I am very new at this. If someone could give me a hard shove in the right direction I would appreciate it.

Rendering Code (the GLUT callback)...

void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,1.0,-1.0,1.0,0.0,1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.0f,1.0f);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3,GL_FLOAT,0,&vertexarray[0]);
glColorPointer(3,GL_FLOAT,0,&vertexcolorarray[0]);
glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_INT,&ind exarray[0]);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

glutSwapBuffers();
}

Triangle I am drawing...


void loadScene()
{
//test vertex0
vertexarray.push_back(-0.5f);
vertexarray.push_back(-0.5f);
vertexarray.push_back(0.0f);
vertexcolorarray.push_back(1.0f);
vertexcolorarray.push_back(0.0f);
vertexcolorarray.push_back(0.0f);
//test vertex1
vertexarray.push_back(0.5f);
vertexarray.push_back(0.0f);
vertexarray.push_back(0.0f);
vertexcolorarray.push_back(0.0f);
vertexcolorarray.push_back(1.0f);
vertexcolorarray.push_back(0.0f);
//test vertex2
vertexarray.push_back(0.0f);
vertexarray.push_back(0.5f);
vertexarray.push_back(0.0f);
vertexcolorarray.push_back(0.0f);
vertexcolorarray.push_back(0.0f);
vertexcolorarray.push_back(1.0f);
//test index
indexarray.push_back(0);
indexarray.push_back(1);
indexarray.push_back(2);
}

BionicBytes
05-27-2011, 09:24 AM
use gluPerspective to setup your projection matrix and gluLookAt to setup your modelview matrix.
You'll find these two function much easier to understand and use (providing you are using compatability profile).