Results 1 to 10 of 10

Thread: draws what's behind other things

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    15

    draws what's behind other things

    Hi,

    I am doing my first project. But for some unknown reason my program also draws what's behind other objects allthough I do not use alpha or anything like that. Maybe somebody knows what I am doing wrong. (It's written in CsGL, that's OpenGL for C#)?

    I added some programmingcode and a screenshot at this link: http://www.vbforums.com/showthread.php?t=410183

    As you can see I first posted my question on a C# forum (with little result so far). My next topics I will place here immediately.

    Thank you in advance for all help !
    Greetings !

  2. #2
    Guest

    Re: draws what's behind other things

    Is depth buffering enabled? Are you using the right comparison function for the depth buffer?

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    15

    Re: draws what's behind other things

    I am not sure. I am still a bit new to it. I think it is enabled:

    is it this?:
    Code :
     protected override void InitGLContext() 
    		{
    			GL.glShadeModel(GL.GL_SMOOTH);         // Set Smooth Shading                 
    			GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);     // BackGround Color         
    			GL.glClearDepth(1.0f);                 // Depth buffer setup             
    			GL.glEnable(GL.GL_DEPTH_TEST);         // Enables Depth Testing             
    			GL.glDepthFunc(GL.GL_LEQUAL);             // The Type Of Depth Test To Do     
    			GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);     /* Really Nice Perspective Calculations */     
    		}
    Greetings !

  4. #4
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: draws what's behind other things

    Maybe when you create your rendering context you use pixel format without depth buffer?

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    15

    Re: draws what's behind other things

    Code :
    			GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    			GL.glLoadIdentity();
    			GL.glTranslatef(paintposx,paintposy, paintposz);
    			GL.glRotatef(angleY, 1.0f, 0.0f, 0.0f);
    			GL.glRotatef(angleZ, 0.0f, 1.0f, 0.0f);
    In the Gl_Draw function I am first doing these and then I start looping though my objects to draw them one by one. Each object has a Paint method as shown on the hyperlink above but I will post the code here too...

    Code :
    		public void Paint()
    		{
    			bool painting = true;
    			switch(points.Count)
    			{
    				case 2:
    					GL.glBegin(GL.GL_LINES);
    					break;
    				case 3:
    					GL.glBegin(GL.GL_TRIANGLES);
    					break;
    				case 4:
    					GL.glBegin(GL.GL_QUADS);
    					break;
    				default:
    					painting = false;
    					break;
    			}
    			if (painting)
    			{
    				for(int i = 0; i < points.Count;i++)
    				{
    					PointMatrix p = (PointMatrix)points[i];
    					GL.glColor3fv(p.Color);
    					GL.glVertex3f(p.X,p.Y,p.Z);
    				}
    				GL.glEnd();
    			}
    		}
    Oh and this my resize function...
    Maybe something is wrong with this one?

    Code :
    		protected override void OnSizeChanged(EventArgs e)
    		{
    			base.OnSizeChanged(e);
     
    			Size s = Size;
    			double aspect_ratio = 1.0; //(double)s.Width /(double) s.Height;
    			GL.glMatrixMode(GL.GL_PROJECTION); // Select The Projection Matrix
    			GL.glLoadIdentity(); // Reset The Projection Matrix
     
    			// Calculate The Aspect Ratio Of The Window
    			GL.gluPerspective(45.0f, aspect_ratio, 0.1f, 100.0f);
     
    			GL.glMatrixMode(GL.GL_MODELVIEW); // Select The Modelview Matrix
    			GL.glLoadIdentity();// Reset The Modelview Matrix
    		}
    Besides this I don't have any OpenGL related code. (Except for the refreshing-thread).

    Thank you for your efforts so far! I really hope to find what's wrong. Strange that I have only this little code and still strange things happen.
    Greetings !

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    15

    Re: draws what's behind other things

    Hmm, I did some additional tests.

    And it turns out he always draws closer objects behind objects which are farther away.

    Also I have the impression that objects even get a little bit smaller as they come closer to the camera.

    Does anybody have any idea why this is happening?
    Greetings !

  7. #7
    Guest

    Re: draws what's behind other things

    Please don't use csgl (not supported anymore) but TAO which is also compatible with mono...

  8. #8
    Guest

    Re: draws what's behind other things

    Can you please post all your rendering code? I don't even see that you're clearing the color/depthbuffer.

    And as stated already, you need to make sure your rendering context is created with a depth buffer (PFD_DOUBLEBUFFER flag and pfd.cDepthBits = 16 or 24), which I guess csgl takes care of for you or you need to explicitly request it as part of initialization.

    I'd also recommend using Tao if you're starting out, although with .NET 2.0 creating a wrapper isn't very difficult, just incredibly tedious.

  9. #9
    Guest

    Re: draws what's behind other things

    And a word of warning: while OpenGL function call overhead generally isn't a big deal in C/C++, it is in C#/.NET (big time). Interop overhead is atrocious and can cut your framerate in half for nontrivial geometry (2000 plus vertices or so). Plan on using vertex arrays/buffers from the get-go or don't be surprised if your framrate isn't what you think it should be!

  10. #10
    Junior Member Newbie
    Join Date
    Jun 2006
    Posts
    15

    Re: draws what's behind other things

    Thank you all, the problem has been fixed. It turns out I was just confusing some things. Sorry that I might have wasted your time.

    I don't know about Tao though. Sounds like I will have to restart again then. A bit painful.
    Greetings !

Similar Threads

  1. Problem with using glDrawElementsBaseVertex - bad draws
    By Dariusz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-13-2019, 01:49 PM
  2. FBO issue: glViewport set, only draws one part
    By OpenGL Developer in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 04-23-2012, 05:56 AM
  3. GL_QUADS draws triangle?
    By polymath in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-23-2010, 10:31 AM
  4. my display func only draws once
    By topekk in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-02-2004, 06:33 AM
  5. Scene only draws after mouse moves
    By Rajveer in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-28-2002, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean