or, more correctly, what is the fundamental bug with my classic untrendy non-shader-VBO-stuff?
cdef struct xyz:
float x, y, z
cdef inline void _normal(xyz b,xyz a):
glNormal3f(a.x-b.x,a.y-b.y,a.z-b.z)
cdef inline void _draw_quad(xyz a,xyz b,xyz c,xyz d):
glVertex3f(a.x,a.y,a.z)
glVertex3f(b.x,b.y,b.z)
glVertex3f(c.x,c.y,c.z)
glVertex3f(d.x,d.y,d.z)
cdef void _draw_grid(xyz a,xyz b,xyz c,xyz d):
glBegin(GL_LINE_LOOP)
_draw_quad(a,b,c,d)
glEnd()
.... # main loop goes through my data array issuing the appropriate functions
while self._buf.remaining() > 0:
op = self._buf.read_char()
if op == _COLOR:
col = self._buf.read_rgb()
#print col
glColor3f(col.r,col.g,col.b)
elif op in (_BOX,_GRID):
tl,tr,br,bl,trb,brb,tlb,blb = self._buf.read_xyz(),self._buf.read_xyz(),\
self._buf.read_xyz(),self._buf.read_xyz(),\
self._buf.read_xyz(),self._buf.read_xyz(),\
self._buf.read_xyz(),self._buf.read_xyz()
if op == _BOX:
#print "box",col
glBegin(GL_QUADS)
func = _draw_quad
else:
#print "grid",col
func = _draw_grid
_normal(tlb,tl)
func(tl,tr,br,bl)
_normal(tl,tr)
func(tr,trb,brb,br)
_normal(tr,tl)
func(tl,tlb,blb,bl)
_normal(tr,tl)
func(tl,tlb,trb,tr)
_normal(tl,tr)
func(bl,blb,brb,br)
_normal(tl,tlb)
func(tlb,trb,brb,blb)
if op == _BOX:
glEnd()
#glFlush()
else:
raise Exception("corrupt serialisation; got %x"%op)
if flush after each cube or wireframe, I get this CORRECT rendering:
if I omit the flush - and I obviously don't want to be flushing, even if I am not treading the most optimal opengl path - then I get this INCORRECT rendering, and this is the bug I don't understand:
For the curious, here is how glutSolidCube
and wires do it: http://www.google.com/codesearch/p?hl=en#xbii4fg5bFw/trunk/FDS/trunk/SMV_5/source/glut-3.7.6/glut_shapes.c&q=glutSolidCube%20lang:c&sa=N&cd=4&ct=rc