Disappearing Models Problem
Hello. I have been using glut to run opengl windows and when I try to translate the screen, my models slowly start to disappear. Here is the main.cpp code.
Code:
#include <stdio.h>
#include <GLUT/glut.h>
#include "Events.h"
#include "Vertex.h"
#include "Model.h"
Events events;
double rot = 0.0;
Model m;
GLfloat LightAmbient[]= { 0.2f, 0.2f, 0.2f, 0.2f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 5.0f, 10.0f, 0.0f, 1.0f };
float time = 0;
float pos[] = {0.0, 0.0, 0.0};
void processNormalKeys(unsigned char key, int x, int y) {
events.keyDown(key);
events.mouseMoved(x, y);
}
void processNormalKeysUp(unsigned char key, int x, int y) {
events.keyUp(key);
events.mouseMoved(x, y);
}
void mouseEvent(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON)
{
if(state==GLUT_DOWN)
{
events.mouseDown(x, y);
}else{
events.mouseUp(x, y);
}
}
}
void mouseMoved(int x, int y)
{
events.mouseMoved(x, y);
}
void init()
{
//glMatrixMode(GL_PROJECTION);
glEnable(GL_DEPTH_TEST);//(NEW) Enable depth testing
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
m.loadLists();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(pos[0], pos[1], pos[2]);
glRotatef(time, 1.0, 1.0, 1.0);
glCallList(m.getList(0));
if(events.getKey('w'))
{
pos[2] += 0.01;
}
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
}
void idle()
{
time += 0.1;// increase our time variable
if(time > 360)
time = 0;// reset time variable
}
int main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(1000,800);
glutInitWindowPosition(100,100);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);//tell the program we are running the depth buffer
m.load("/Users/mendel/Desktop/lump.obj");
glutCreateWindow("Lesson 4");
//glutFullScreen();
init();
glutKeyboardFunc(processNormalKeys);
glutKeyboardUpFunc(processNormalKeysUp);
glutMotionFunc(mouseMoved);
glutPassiveMotionFunc(mouseMoved);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(idle);// This function calls our idle function to update our variables
glutMainLoop();
return 1;
}
glMatrixMode(GL_MODELVIEW); in the right place will do wonders. You might also want to revise your glutInitDisplayMode() call.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenAL - sound disappearing | Madrayken | 3 | 3,865 |
Jan 19, 2010 03:22 AM Last Post: Madrayken |
|
| Nice models and free models, new site! | 3d4ya | 4 | 3,429 |
Sep 18, 2008 07:36 AM Last Post: NYGhost |
|

