model not showing in scene

Started by
1 comment, last by meeshoo 12 years, 1 month ago
Hi again,
Firstly, Thank you soo much community for helping me with my last dilemma.
all bugs from that are fixed now, the only problem is when i call the model to be rendered it doesn't show in the viewport.
can anyone shed any light on this?

heres the main.cpp

#include "main.h"
#include "3dsloader.h"


void lighting();
void initRendering();
void drawScene();
void mainLoop();

Object* testcube;

int main(int argc, char **argv)
{
bool running = true;

InitializeWindow();

testcube = new Object("apex.3ds");

initRendering();

testcube->CreateVBO();

mainLoop();

return 0;
}
void initRendering()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
// Enable lighting and set the position of the light
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
GLfloat pos[] = { 0.0, 4.0, 4.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);

}

void mainLoop(void)
{
// the time of the previous frame
double old_time = glfwGetTime();
// this just loops as long as the program runs
while(1)
{
// escape to quit, arrow keys to rotate view
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
break;

// draw the figure
drawScene();

// swap back and front buffers
glfwSwapBuffers();
}
}
void drawScene()
{
//clear info from last draw
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(0.0f, 0.0f, -5.0f); // translate camera
// ADD SCENE OBJECTS TO RENDER HERE
testcube->Draw();
glfwSwapBuffers();
};
void shutdown()
{
glfwTerminate();
delete testcube;
exit(1);
}


all the other headers arent necessary but if you think they are, they can be found here->
http://www.gamedev.net/topic/621666-debug-assertion-failed-on-game-project/

Thankyou :)
Advertisement
I'm going to assume that you've set up the projection matrix elsewhere in your code, and then switched back into GL_MODELVIEW mode...
Every frame, you call glTranslatef, which concatenates a translation of z-5 units onto the model-view matrix. Since you don't call glLoadIdentity each frame, then after 100 frames, your camera has been translated by 500 units in the z axis, etc, until it flies off into infinity.
I recommend this free online book to anyone starting in graphics programming, especially with OpenGL.

This topic is closed to new replies.

Advertisement