Hi,
I'm new to OpenGL and am experimenting with a program like the one below
(OpenGL in SDL, but that should not matter); this draws two squares
"stacked" and lets them rotate around the y-axis.
I expected to see at times both the green and the red one on top of the
other because of the rotation, but it seems that always the red one is
on top. I even tried disabling the rotation entirely and changing the
z-coordinate of the green one to -0.1 (and back) but in *both* of these
cases the red square was still on top of the other (and nothing green
visible at all).
Does this mean that OpenGL simply draws polygons on top of each other
and does not take into account visibility (that is, that's my
responsibility)? If so, are there any pointers you could give me on how
to implement this most effectively? Or what's wrong with my program?
BTW, the experiment with changing the z-coordinate not even gives me a
green "border" so regardless of the distance from the viewer the size is
always the same. Does OpenGL simply perform an orthogonal projection
onto the XY-plane?
Thanks for clarification and I'm sure I've misunderstood something
completely,
Daniel
======= test.c =======
#include "SDL.h"
#include "SDL_opengl.h"
#include <stdlib.h>
void render (double theta)
{
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix ();
glRotated (theta, 0., 1., 0.);
glScaled (.25, .25, .25);
glBegin (GL_QUADS);
glColor3d (0., 1., 0.);
glVertex3d (0., 0., 0.1);
glVertex3d (1., 0., 0.1);
glVertex3d (1., 1., 0.1);
glVertex3d (0., 1., 0.1);
glColor3d (1., 0., 0.);
glVertex3d (0., 0., 0.);
glVertex3d (1., 0., 0.);
glVertex3d (1., 1., 0.);
glVertex3d (0., 1., 0.);
glEnd ();
glPopMatrix ();
SDL_GL_SwapBuffers ();
}
int main (int argc, char** argv)
{
SDL_Surface* surf;
int done = 0;
double theta = 0.;
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
return EXIT_FAILURE;
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
surf = SDL_SetVideoMode (640, 480, 0, SDL_OPENGL);
if (!surf)
return EXIT_FAILURE;
while (!done)
{
SDL_Event evt;
while (SDL_PollEvent (&evt))
switch (evt.type)
{
case SDL_QUIT:
done = 1;
break;
}
render (theta);
SDL_Delay (10);
theta += 1;
}
SDL_Quit ();
return EXIT_SUCCESS;
}
=================
--
Done: Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
Underway: Ran-Gno-Neu-Fem
To go: Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou


|