private void glControl_Paint(object sender, PaintEventArgs e) { Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glLoadIdentity(); // Setup wireframe or solid fill drawing mode if (Wireframe) { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE); } else { Gl.glPolygonMode(Gl.GL_FRONT, Gl.GL_FILL); } Vector3 center = Vector3.Zero; Glu.gluLookAt( center.X, (double)scrollZoom.Value * 0.1d + center.Y, center.Z, center.X, center.Y, center.Z, 0d, 0d, 1d); // Push the world matrix Gl.glPushMatrix(); Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY); Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); // World rotations Gl.glRotatef((float)scrollRoll.Value, 1f, 0f, 0f); Gl.glRotatef((float)scrollPitch.Value, 0f, 1f, 0f); Gl.glRotatef((float)scrollYaw.Value, 0f, 0f, 1f); if (Prims != null) { for (int i = 0; i < Prims.Count; i++) { Primitive prim = Prims[i].Prim; if (i == cboPrim.SelectedIndex) { Gl.glColor3f(1f, 0f, 0f); } else { Gl.glColor3f(1f, 1f, 1f); } // Individual prim matrix Gl.glPushMatrix(); // The root prim position is sim-relative, while child prim positions are // parent-relative. We want to apply parent-relative translations but not // sim-relative ones if (Prims[i].Prim.ParentID != 0) { // Apply prim translation and rotation Gl.glMultMatrixf(Math3D.CreateTranslationMatrix(prim.Position)); Gl.glMultMatrixf(Math3D.CreateRotationMatrix(prim.Rotation)); } // Prim scaling Gl.glScalef(prim.Scale.X, prim.Scale.Y, prim.Scale.Z); // Draw the prim faces for (int j = 0; j < Prims[i].Faces.Count; j++) { if (i == cboPrim.SelectedIndex) { // This prim is currently selected in the dropdown //Gl.glColor3f(0f, 1f, 0f); Gl.glColor3f(1f, 1f, 1f); if (j == cboFace.SelectedIndex) { // This face is currently selected in the dropdown } else { // This face is not currently selected in the dropdown } } else { // This prim is not currently selected in the dropdown Gl.glColor3f(1f, 1f, 1f); } #region Texturing Face face = Prims[i].Faces[j]; FaceData data = (FaceData)face.UserData; if (data.TexturePointer != 0) { // Set the color to solid white so the texture is not altered //Gl.glColor3f(1f, 1f, 1f); // Enable texturing for this face Gl.glEnable(Gl.GL_TEXTURE_2D); } else { Gl.glDisable(Gl.GL_TEXTURE_2D); } // Bind the texture Gl.glBindTexture(Gl.GL_TEXTURE_2D, data.TexturePointer); #endregion Texturing Gl.glTexCoordPointer(2, Gl.GL_FLOAT, 0, data.TexCoords); Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, data.Vertices); Gl.glDrawElements(Gl.GL_TRIANGLES, data.Indices.Length, Gl.GL_UNSIGNED_SHORT, data.Indices); } // Pop the prim matrix Gl.glPopMatrix(); } } // Pop the world matrix Gl.glPopMatrix(); Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY); Gl.glFlush(); }