Wineglass doesn't render properly

NOTE: I haven’t had much luck getting this to compile using g++ because of my Vector class. It definitely compiles in MS Visual Studio, though. The compiler errors in g++ aren’t what I’m trying to fix, though a friend of mine was able to get it compiling on his PC (he uses g++) by removing all instances of Vector& from Vector, and passing it by value instead.

DESCRIPTION OF PROBLEM:
The way the program works is that it reads in an SDL file. The SDL file contains information about the scene: the light positions, colors, etc. It also contains information about the materials used in the scene. It then contains a line which directs you to the file that contains all the mesh information (a .3VN file - formatted as follows:
<3 tuple containing: # of vertices, # of normals, # of faces for object>
<List of 3 tuples corresponding to the vertices of the object>
<List of 3 tuples corresponding to the normals of the object>
<Foreach face in the object:

of vertices in face

for each vertex in the face
indices of vertices in the list of vertices
indices of normals in the list of normals>)
I then attempt to render (using OpenGL with GLUT) the object described by the SDL/3VN file(s). The problem is that when it renders, it looks incorrect. That is, the object is clearly missing triangles when it’s being drawn. It looks very choppy. The code is kind of long, so I’m going to post it on another site.

Source is at:
http://www.freewebs.com/volatilevoid/Camera.h
http://www.freewebs.com/volatilevoid/Camera.cpp
http://www.freewebs.com/volatilevoid/Vector.h
http://www.freewebs.com/volatilevoid/Mesh.h
http://www.freewebs.com/volatilevoid/CubeMain.cpp

Scene files:
http://www.freewebs.com/volatilevoid/pewterglass.sdl
http://www.freewebs.com/volatilevoid/glass.3vn

I confirmed that both the SDL and 3VN files are being read in correctly, so I’m really at a loss as to what’s wrong. I apologize for the messiness of my code: I kept adding in debugging output and removing it, and moved so much stuff around to try to find the problem that I made my code look like a trainwreck. I’m also going to post a much shorter SDL/3VN file, since it might be easier to find the problem with a less complex object:

Other scene files:
http://www.freewebs.com/volatilevoid/Cube.sdl
http://www.freewebs.com/volatilevoid/Cube.3vn

Note, to move around in the scene see the key() function in CubeMain.cpp
‘x’ rotates on the XZ plane (‘X’ rotates in the opposite direction on the XZ plane)
‘y’ rotates on the YZ plane (‘Y’ - opposite direction)
‘l’ slides on the X axis
‘k’ slides on the Y axis
‘j’ slides on the Z axis
‘t’ tilts
‘p’ pans
‘r’ rolls

EDIT: I realize I have a memory leak where I read in the file, new a Mesh and never delete it. While that’s a problem, it’s not THE problem that’s causing improper rendering. I’ll add in code to clean up the leak (after glutMainLoop () releases, I can clean up the mesh).

Thanks in advance. :slight_smile:
VV

Here’s a pic of what it looks like when it renders.

I didn’t look thru your source but…

It seems pretty obvious that either the source
file from which you are rendering is ill-defined
or you aren’t parsing it correctly.

Also, how are you rendering? Quads? Triangles?
Triangle strips?

The vertices in the file are defined for a certain
type of primitive…you should ensure that you’re
rendering the right type.

I confirmed that both the SDL and 3VN files are being read in correctly, so I’m really at a loss as to what’s wrong

  • How did you confirm this? What makes you sure?

This may not be the problem, but I think it’s a
good place to start.

Originally posted by Aeluned:
[b]I didn’t look thru your source but…

It seems pretty obvious that either the source
file from which you are rendering is ill-defined
or you aren’t parsing it correctly.

Also, how are you rendering? Quads? Triangles?
Triangle strips?

The vertices in the file are defined for a certain
type of primitive…you should ensure that you’re
rendering the right type.

This may not be the problem, but I think it’s a
good place to start.[/b]
The rendering type is POLYGON.
I know the file is correct as it came with my textbook, and the binary that came with my text renders the file correctly, so I’m certain it’s something with my code.

Make these changes to CubeMain.cpp to fix your
issues:

in main()
you had:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
so you weren’t getting a depth buffer to work with

change to:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA |
GLUT_DEPTH);

Also, the normals you are reading in need to be
normalized in order to get proper lighting

so:
glEnable(GL_NORMALIZE);

finally push back your near clip plane;
a near clip plane at 0.0 isn’t a good idea.

I opted for 0.1

so:
gluPerspective (45.0f, w/h, 0.1f, 70.0f);

that should work.

oh, and be sure to uncomment
glEnable(GL_DEPTH_TEST) in main().

Ah, moving the near plane of the frustum from 0.0 to 0.1 fixed it. All the normals are normalized in the 3vn file, but I enabled GL_NORMALIZE to be sure.

Thanks a lot! :slight_smile: