PDA

View Full Version : Basic OpenGL Model loading



Menta2K
12-27-2014, 10:15 AM
Hello i am a real beginner so please dont blame me for my question probably it sounds very stupid.

Basically i am traing do display Unreal Engine Model.
The structure of the Model is with several surfices.Each surfice have own Vertex normals indexes and UVs.
And here is the code itself


private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
{
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.ShadeModel(OpenGL.GL_SMOOTH);
gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);


}
private void DrawMesh2()
{
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.Color(1.0f, 1.0f, 1.0f);
gl.LoadIdentity();
gl.LookAt(50, 50, 50, 0, 0.5f, 0, 0, 1, 0);
gl.Rotate(0, rotation++, rotation / 2);


for (int i = 0; i < m_Model.Surfices.Count; i++)
{
int k = 0;
gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[i]);
gl.Enable(OpenGL.GL_TEXTURE_2D);
gl.Begin(OpenGL.GL_TRIANGLES);
for (int j = 0; j < m_Model.Surfices[i].triangle_count; j++) {
gl.Normal(m_Model.Surfices[i].Verteces[k].Normal.ToArray());
gl.TexCoord(m_Model.Surfices[i].TextureCords[k].UV.ToArray());
gl.Vertex(m_Model.Surfices[i].Verteces[k].Location.ToArray());

gl.Normal(m_Model.Surfices[i].Verteces[k+1].Normal.ToArray());
gl.TexCoord(m_Model.Surfices[i].TextureCords[k+1].UV.ToArray());
gl.Vertex(m_Model.Surfices[i].Verteces[k+1].Location.ToArray());

gl.Normal(m_Model.Surfices[i].Verteces[k+2].Normal.ToArray());
gl.TexCoord(m_Model.Surfices[i].TextureCords[k+2].UV.ToArray());
gl.Vertex(m_Model.Surfices[i].Verteces[k+2].Location.ToArray());
k += 3;
}
gl.End();
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
gl.Disable(OpenGL.GL_TEXTURE_2D);

}
gl.End();
gl.Flush();
}


The result looks like this:
1575
But should look like
1576
So my guess is that the texture of the first or last Surfice is used

I will strongly appreciate any help or directions what may be wrong

DragonForce99
12-30-2014, 06:54 PM
1- you dont have to call gl.Enable(OpenGL.GL_TEXTURE_2D); many times in loop function one time is enough then Disable when you dont need it
and so (gl.Disable(OpenGL.GL_TEXTURE_2D);)
2- to check which texture is wrong
(gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);
use first texture then try next texture (textures[1])
texture may didn't loaded or maybe the problem with (texcoord)