Disappearing Models Problem

Posts: 40
Joined: 2008.10
Post: #1
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.

#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.mouseMoved(x, y);

void processNormalKeysUp(unsigned char key, int x, int y) {
    events.mouseMoved(x, y);

void mouseEvent(int button, int state, int x, int y)
            events.mouseDown(x, y);
            events.mouseUp(x, y);
void mouseMoved(int x, int y)
    events.mouseMoved(x, y);
void init()

    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);
void display()
    glTranslatef(pos[0], pos[1], pos[2]);
    glRotatef(time, 1.0, 1.0, 1.0);
        pos[2] += 0.01;

void reshape(int width, int height)
    glViewport(0, 0, width, height);
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);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);//tell the program we are running the depth buffer
    glutCreateWindow("Lesson 4");
    glutIdleFunc(idle);// This function calls our idle function to update our variables
    return 1;
Quote this message in a reply
Posts: 869
Joined: 2003.01
Post: #2
glMatrixMode(GL_MODELVIEW); in the right place will do wonders. You might also want to revise your glutInitDisplayMode() call.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenAL - sound disappearing Madrayken 3 5,283 Jan 19, 2010 03:22 AM
Last Post: Madrayken
  Nice models and free models, new site! 3d4ya 4 4,589 Sep 18, 2008 07:36 AM
Last Post: NYGhost