Well, I don't see how OpenGL automatically creates
normals. In all examples with light and n-gons (strips, quads, etc.)
the normals are explicit. Thus, we can have the utility
verb to optionally automatically generate the normals,
as shown below. Though I don't like the result very much:
there's definitely some normals, but are they correct?
P=: +. (4%:_1)*^:(<8) 1 NB. regular planar octagon
P0=: P,._1
P1=: P,. 1
Q=: _3]\,P0,.P1 NB. quad strip (last not added to look inside)
GS_AMBIENT=: 0.15
GS_DIFFUSE=: 0.7
GS_SPECULAR=: 0.7
GS_ROTXYZ=: 25 40 0
paint=: 3 : 0
gsinit GS_LIGHT
gsdrawviewbox RED
gsdrawpolygon P0;'';RED
gsdrawpolygon P1;'';BLUE
gsdrawquadstrip Q;'';GREEN
gsfini''
)
NB. ========================= TBD in jzopenglutil.ijs ===
gsnormal=: (% +/&.(*:"_))@(+/)
gsquadnormal=: (2,:4)&(gsnormal;._3)
gsdrawquadstrip=: 3 : 0 "2
'v n c'=. y
v=. gscol3 v
if. 0=#n do. n=. gsquadnormal v end.
if. #c do. gscolor c end.
glBegin GL_QUAD_STRIP
for_i. i.&.-: #v do.
if. i>0 do. glNormal (-:i-2){n end.
glVertex (i+i.2){v
end.
glEnd''
)
----- Original Message ----
From: "Miller, Raul D" <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Thursday, July 27, 2006 8:08:39 PM
Subject: RE: [Jprogramming] opengl geometry meshes?
Oleg Kobchenko wrote:
> Here's the simplest I could think of.
> But no triangles here: a polygon and a quad strip.
Thanks.
I'll try to look at it in more depth when I have the
chance to figure out jzopenglutil.
> The problem here is light/normals: it looks like
> OpenGL cannot automatically figure out normals (?).
That's odd. Normally it does.
And they're extremely simple to figure out --
take the (3d) cross product of the two vectors
leading out from any corner of a face, and the
result is normal to that face. Divide by the
length and you have the normal.
I was under the impression that opengl did
this by default unless you configured it
such that you're providing normals manually.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm