PDA

View Full Version : Problem with glTranslate*()



arefaslani
03-13-2012, 11:42 AM
hello everyone!!! I'm Aref Aslani and I'm new to openGL.
I have a problem with glTranslate*()! when i move some object on for example z axis more than 1 unit it no more visible...
for example: glTranslatef(0, 0, -5)
I expect that the object have been seen smaller, but i cant see anything...
please help me...
P.S. forgive me for my poor english

menzel
03-13-2012, 11:45 AM
Sounds like you don't have a projection matrix or your far plane is at -1.

anton1212
03-13-2012, 02:53 PM
It's very simple, you have moved your object but your camera's pointing to the origin from the default values. Try to put the code of the bottom into the Display function before the "glutSwapBuffers();" and the "glFlush();" and tell us if it worked well.


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-20.0f,20.0f,-20.0f,20.0f,-20.0,20.0f);

arefaslani
03-15-2012, 12:29 AM
Thank you a lot menzel and anton1212...
I tested gluPerspective and i see some results...
Do you think this is my problem?
P.S. This is my code:

#include "stdafx.h"
#include <glut.h>

void display();
void init();

void main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(500, 500);
glutCreateWindow("Test GLUT");
init();
glutDisplayFunc(display);
glutMainLoop();
}

void init()
{
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 0, 0);
}

void display()
{
glPointSize(50);
//LOOK HERE! IF I CHANGE -1.2 to -1 I WILL SEE A BIG POINT,ELSE NOTHING...
gluPerspective(45, 1, 0, 7);
glTranslatef(0, 0, -100);
glBegin(GL_POINTS);
glVertex2d(0, 0);
glEnd();

//I TESTED YOUR CODE ANTON1212, BUT NOTHING CHANGED...
//glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
//glOrtho(-20.0f,20.0f,-20.0f,20.0f,-20.0,20.0f);
glutSwapBuffers();
}