0

I am using xcode with glut, OpenGL and c++ and I am trying to import and draw a model. I have used an obj to .h file conversion and this is a small part of the header so you can see the structure.

unsigned int M4GunNumVerts = 37812;
GLfloat M4GunVerts [] = {
// f 1/1/1 1582/2/1 4733/3/1
{0.266494348503772, 0.0252334302709736, -0.000725898139236535},
{0.265592372987502, 0.0157389511523397, -0.000725898139236535},
{0.264890836474847, 0.0182004476109518, -0.00775888079925833},

I have tried to draw this in my main with this code.

glVertexPointer(3, GL_FLOAT, 0, M4GunVerts);
glNormalPointer(GL_FLOAT, 0, M4GunNormals);
glTexCoordPointer(2, GL_FLOAT, 0, M4GunTexCoords);
glDrawArrays(GL_TRIANGLES, 0, M4GunNumVerts);

When I run I cant see the model. I have set up a glut window and have made a triangle to see if shapes were being drawn and the triangle showed up. I don't know how fix this so I can see the model.

Here is the reshape function

  glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glViewport(0, 0, w, h);

gluPerspective(45, ratio, 0.01, 1000);

glMatrixMode(GL_MODELVIEW);

Can anybody help?

genpfault
  • 51,148
  • 11
  • 85
  • 139
David Graovac
  • 55
  • 2
  • 3
  • 7
  • 1
    You have not provided enough information to answer this question. Coordinate spaces are very important in OpenGL, without knowing your projection and modelview matrices any number of things could be wrong. Additionally, you have not enabled any vertex array pointers in the minimal code snippet you provided. Please provide more code that includes both of these things. – Andon M. Coleman Oct 20 '13 at 19:55
  • I have enabled the vertex array points but I didnt include it. And I added some code. – David Graovac Oct 20 '13 at 20:05
  • @DavidGraovac: Please don't use things like "obj to h" converters. Instead use a library like ASSIMP to load the model data from a file. – datenwolf Oct 20 '13 at 20:33

1 Answers1

0

Either you:

  • do not enable arrays correctly
  • and or your camera view is in wrong direction to your object
  • and or your camera is inside the object. (while CULL_FACE is enabled)
  • and or wrongly or none at all glColor !!! (can not see black on black)
  • and or forget to bind texture (while enabled)
  • and or wrong glTexCoord (while enabled)
  • and or wrongly set lights (while enabled)
  • and or wrong perspective respect to object distance and size (view angle,znear,zfar)
  • if object is planar and you are looking on the thin side ...

Some hints:

Try to rotate camera around the scene (ideal with some keys like arrows and see if the object is behind... or mouse drag...). Also try to move your camera forward/backward (also can use keys but my favorite is mouse wheel).

Use glBegin() glVertex() glEnd() first to avoid problems with wrongly enabled arrays and start without lighting,textures,CULL_FACEing (have them disabled!!!). When you see your model then enable all incrementally so you see what is wrong. After all is OK then try arrays.

If your object seems the wrong way about while CULL_FACE enabled then your winding rule is wrong (CW/CCW) can be seen mostly while rotating object

here is simple OpenGL scene app in BDS2006 you can use it as test of your window and camera/model matrix settings

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380