enablerbr's picture

NeHe lesson 5 problem.

i couldn't work out how to take and save a screenshot from my app. so i've uploaded the program exe. the trouble is some of the faces seem to just dissapear. so instead of seeing a solid cube. you see the inside of a cube at times and other times you see the outside ot the cube. i'm not sure what is causing it. as i checked the code and it matches the NeHe code.

AttachmentSize
NeHeLesson5.rar342.04 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
puklaus's picture

Check that normals are right (if used), and culling (front/back)
oop check you had zbuffer (depthbuffer) used.
But I think, there is some normals wrong.

enablerbr's picture

heres the code.

private void glControl1_Load(object sender, EventArgs e)
        {
            GL.ShadeModel(ShadingModel.Smooth);							// Enable Smooth Shading
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.5f);				                        // Black Background
            GL.ClearDepth(1.0f);									                    // Depth Buffer Setup
            GL.Enable(EnableCap.DepthTest);							    // Enables Depth Testing
            GL.DepthFunc(DepthFunction.Lequal);							// The Type Of Depth Testing To Do
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
        }
 
        private void glControl1_Resize(object sender, EventArgs e)
        {
            if (glControl1.ClientSize.Height == 0)
                glControl1.ClientSize = new System.Drawing.Size(glControl1.ClientSize.Width, 1);
 
            GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
 
            GL.MatrixMode(MatrixMode.Projection);						// Select The Projection Matrix
            GL.LoadIdentity();									                        // Reset The Projection Matrix
 
            // Calculate The Aspect Ratio Of The Window
            Glu.Perspective(45.0f, (double)glControl1.Width / (double)glControl1.Height, 0.1f, 100.0f);
 
            GL.MatrixMode(MatrixMode.Modelview);					    // Select The Modelview Matrix
            GL.LoadIdentity();
        }
 
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);	// Clear Screen And Depth Buffer
            GL.LoadIdentity();									// Reset The Current Modelview Matrix
            GL.Translate(-1.5f, 0.0f, -6.0f);					// Move Left 1.5 Units And Into The Screen 6.0
            GL.Rotate(rtri, 0.0f, 1.0f, 0.0f);				    // Rotate The Triangle On The Y axis ( NEW )
            GL.Begin(BeginMode.Triangles);						// Start Drawing A Triangle
            GL.Color3(1.0f, 0.0f, 0.0f);						// Red
            GL.Vertex3(0.0f, 1.0f, 0.0f);					    // Top Of Triangle (Front)
            GL.Color3(0.0f, 1.0f, 0.0f);						// Green
            GL.Vertex3(-1.0f, -1.0f, 1.0f);					    // Left Of Triangle (Front)
            GL.Color3(0.0f, 0.0f, 1.0f);						// Blue
            GL.Vertex3(1.0f, -1.0f, 1.0f);					    // Right Of Triangle (Front)
            GL.Color3(1.0f, 0.0f, 0.0f);						// Red
            GL.Vertex3(0.0f, 1.0f, 0.0f);					    // Top Of Triangle (Right)
            GL.Color3(0.0f, 0.0f, 1.0f);						// Blue
            GL.Vertex3(1.0f, -1.0f, 1.0f);					    // Left Of Triangle (Right)
            GL.Color3(0.0f, 1.0f, 0.0f);						// Green
            GL.Vertex3(1.0f, -1.0f, -1.0f);					    // Right Of Triangle (Right)
            GL.Color3(1.0f, 0.0f, 0.0f);						// Red
            GL.Vertex3(0.0f, 1.0f, 0.0f);					    // Top Of Triangle (Back)
            GL.Color3(0.0f, 1.0f, 0.0f);						// Green
            GL.Vertex3(1.0f, -1.0f, -1.0f);					    // Left Of Triangle (Back)
            GL.Color3(0.0f, 0.0f, 1.0f);						// Blue
            GL.Vertex3(-1.0f, -1.0f, -1.0f);					// Right Of Triangle (Back)
            GL.Color3(1.0f, 0.0f, 0.0f);						// Red
            GL.Vertex3(0.0f, 1.0f, 0.0f);					    // Top Of Triangle (Left)
            GL.Color3(0.0f, 0.0f, 1.0f);						// Blue
            GL.Vertex3(-1.0f, -1.0f, -1.0f);					// Left Of Triangle (Left)
            GL.Color3(0.0f, 1.0f, 0.0f);						// Green
            GL.Vertex3(-1.0f, -1.0f, 1.0f);					    // Right Of Triangle (Left)
            GL.End();											// Done Drawing The Pyramid
 
            GL.LoadIdentity();									// Reset The Current Modelview Matrix
            GL.Translate(1.5f, 0.0f, -7.0f);					// Move Right 1.5 Units And Into The Screen 7.0
            GL.Rotate(rquad, 1.0f, 1.0f, 1.0f);					// Rotate The Quad On The X axis ( NEW )
            GL.Begin(BeginMode.Quads);			                // Draw A Quad
            GL.Color3(0.0f, 1.0f, 0.0f);						// Set The Color To Green
            GL.Vertex3(1.0f, 1.0f, -1.0f);					    // Top Right Of The Quad (Top)
            GL.Vertex3(-1.0f, 1.0f, -1.0f);					    // Top Left Of The Quad (Top)
            GL.Vertex3(-1.0f, 1.0f, 1.0f);					    // Bottom Left Of The Quad (Top)
            GL.Vertex3(1.0f, 1.0f, 1.0f);					    // Bottom Right Of The Quad (Top)
            GL.Color3(1.0f, 0.5f, 0.0f);						// Set The Color To Orange
            GL.Vertex3(1.0f, -1.0f, 1.0f);					    // Top Right Of The Quad (Bottom)
            GL.Vertex3(-1.0f, -1.0f, 1.0f);					    // Top Left Of The Quad (Bottom)
            GL.Vertex3(-1.0f, -1.0f, -1.0f);					// Bottom Left Of The Quad (Bottom)
            GL.Vertex3(1.0f, -1.0f, -1.0f);					    // Bottom Right Of The Quad (Bottom)
            GL.Color3(1.0f, 0.0f, 0.0f);						// Set The Color To Red
            GL.Vertex3(1.0f, 1.0f, 1.0f);					    // Top Right Of The Quad (Front)
            GL.Vertex3(-1.0f, 1.0f, 1.0f);					    // Top Left Of The Quad (Front)
            GL.Vertex3(-1.0f, -1.0f, 1.0f);					    // Bottom Left Of The Quad (Front)
            GL.Vertex3(1.0f, -1.0f, 1.0f);					    // Bottom Right Of The Quad (Front)
            GL.Color3(1.0f, 1.0f, 0.0f);						// Set The Color To Yellow
            GL.Vertex3(1.0f, -1.0f, -1.0f);					    // Top Right Of The Quad (Back)
            GL.Vertex3(-1.0f, -1.0f, -1.0f);					// Top Left Of The Quad (Back)
            GL.Vertex3(-1.0f, 1.0f, -1.0f);					    // Bottom Left Of The Quad (Back)
            GL.Vertex3(1.0f, 1.0f, -1.0f);					    // Bottom Right Of The Quad (Back)
            GL.Color3(0.0f, 0.0f, 1.0f);						// Set The Color To Blue
            GL.Vertex3(-1.0f, 1.0f, 1.0f);					    // Top Right Of The Quad (Left)
            GL.Vertex3(-1.0f, 1.0f, -1.0f);					    // Top Left Of The Quad (Left)
            GL.Vertex3(-1.0f, -1.0f, -1.0f);					// Bottom Left Of The Quad (Left)
            GL.Vertex3(-1.0f, -1.0f, 1.0f);					    // Bottom Right Of The Quad (Left)
            GL.Color3(1.0f, 0.0f, 1.0f);						// Set The Color To Violet
            GL.Vertex3(1.0f, 1.0f, -1.0f);					    // Top Right Of The Quad (Right)
            GL.Vertex3(1.0f, 1.0f, 1.0f);					    // Top Left Of The Quad (Right)
            GL.Vertex3(1.0f, -1.0f, 1.0f);					    // Bottom Left Of The Quad (Right)
            GL.Vertex3(1.0f, -1.0f, -1.0f);					    // Bottom Right Of The Quad (Right)
            GL.End();											// Done Drawing The Quad
 
            rtri += 0.2f;											// Increase The Rotation Variable For The Triangle ( NEW )
            rquad -= 0.15f;										    // Decrease The Rotation Variable For The Quad ( NEW )
 
            glControl1.SwapBuffers();
 
            glControl1.Invalidate();
        }

see i thought depthbuffer. yet i think that is covered in the glControl1_Load section.

puklaus's picture

Because you dont use normals, try

GL.Disable(EnableCap.CullFace);

if these faces shows then.

(this is just your test, i think, but when loading bigger objects, always load normals/calculate them so culling works (faster)).

enablerbr's picture

GL.Disable(EnableCap.CullFace); had no effect.

solved my problem. it was do with where i was placing my code. moved my code from glControl1_Load to OnLoad. then it worked.