ANY help? heres the code...

hello, theres something wrong about my code and i cant find the problem! i know it is a stupid mistake cause it never happened to me…

#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
//#include <stdio.h>
//#include <stdlib.h>

GLdouble orthoX1 = -50.0;
GLdouble orthoY1 = +50.0;
GLdouble orthoX2 = -50.0;
GLdouble orthoY2 = +50.0;

GLfloat windowWidth,windowHeight;
GLfloat xjanela, yjanela;

GLint LARGURA = 334;
GLint ALTURA = 334;

void inicializa(void){
glClearColor(1,0,0,1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH);
}

void Render(void){

glClear(GL_COLOR_BUFFER_BIT);

glLineWidth(2);
glBegin(GL_LINES);

glColor3f(0,0,0);
glVertex3f(0,-5,+2);
glVertex3f(0,5,+2);

glColor3f(0,1,0);
glVertex3f(2,-5,-2);
glVertex3f(2,5,-2);

glColor3f(1,1,1);
glVertex3f(-5,0,0);
glVertex3f(5,0,0);

glEnd();
glFlush();

}

void Reshape(int w, int h){
glViewport(0, 0,(GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(orthoX1, orthoY1, orthoX2, orthoY2, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutPostRedisplay();}

void main()
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(LARGURA,ALTURA);
glutInitWindowPosition(350,250);
glutCreateWindow(“camera”);

inicializa();

glutDisplayFunc(Render);
glutReshapeFunc(Reshape);

glutMainLoop();

}

Ok… so the green line should be far, the white in the middle, and the black in the front… but they appear in the order i draw them… the last one to be called will became the closest to the camera… why?
thanks =))

This may be wrong since I don’t use glut.

You don’t clear your depth buffer in glColor.
Set the parameters to “GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT”.

I can’t remember how I went with glOrtho last time I used it, but shouldn’t the near plane be positive and the far negative?

By the away: Se renomeasses as variáveis para inglês, talvez tiveses mais pessoas a ler o teu código ) Boa sorte

I believe it should be glEnable(GL_DEPTH_TEST)
not GL_DEPTH

Very intersting thing happens when I did the following to the code as well as place the DEPTH items mentioned in the other two posts…

With the two extra lines at the end you get a flickering effect but if you look closely you can see that as it draws the items it really does attempt to place them in the correct sequence with the black line at the bottom, then the white line, then the green line at the front…

Other than that I can’t see how this would work as I have always thought that Ortho was used for 2D work and thus not use the dimensional value of ‘z’ axis.

Tina http://programming.swangen.co.uk/opengl/

===================================
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex3f(0,-10,+2);glVertex3f(0,10,+2);
glColor3f(0,1,0);
glVertex3f(20,-10,-2);glVertex3f(20,10,-2);
glColor3f(1,1,1);
glVertex3f(-50,0,0);glVertex3f(50,0,0);
glEnd();
glFlush();
glutSwapBuffers();
glutPostRedisplay();

ortho is just another projection type, but with no vanishing point. so lines in z direction appear parallel