Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Graphics > OpenGL 3D API > Order of render...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4827 of 5017
Post > Topic >>

Order of rendering

by Daniel Kraft <d@[EMAIL PROTECTED] > Jul 8, 2008 at 04:16 PM

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
 




 4 Posts in Topic:
Order of rendering
Daniel Kraft <d@[EMAIL  2008-07-08 16:16:25 
Re: Order of rendering
folays <folays@[EMAIL   2008-07-08 16:55:44 
Re: Order of rendering
Daniel Kraft <d@[EMAIL  2008-07-08 17:27:46 
Re: Order of rendering
fungus <openglMYSOCKS@  2008-07-08 23:28:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 6:15:28 CST 2008.