Yes, I only now remember discovering with
disappointment that openGL seems to require always repeating
the pairs glNormal and glVertex for *every* vertex. That is
why your (efficient) for. loop in this version of
gsdrawquadstrip does not normalize correctly (glNormal is
finessed alternately).

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''
)

        Your clever use of cut tesselations especially in
combination with gsvertnorm in your most recent version,
really appeals to me because it shows how to eliminate the
for. loop with a more natural loopless J "glBegin...glEnd
bracketed sequence".  (see your revised gsdrawquadstrip
below).

gsvertnorm=: glVertex [ [EMAIL PROTECTED]
gsquadnorms=: (2,:4)&(gsvertnorm;._3)

gsdrawquadstrip=: 3 : 0 "2
  'v n c'=. y
  v=. gscol3 v
  if. #c do. gscolor c end.
  glBegin GL_QUAD_STRIP
  gsquadnorms v
  glEnd''
)

        Thanks. And I also see the graphic differences that
were invisible to me before.

(B=)

On Sat, 29 Jul 2006, Oleg Kobchenko wrote:

+ Here's a version that has the correct appearence.
+ However, it does it at the expense of repeating
+ the edges of the quads, so each normal applies to
+ each set of separately added four vertices, which is
+ not good either.
+
+ Another idea is that probably the normal should be
+ calculated by the edge and not by the face, since in
+ the unadulterated quad strip each face is added only
+ with another edge. The value of the edge normal would
+ be the average of the two adjacent face normals.
+ Does that make sense?
+
+ NB. =========================================================
+
+ gsngon=: 3 : '+. (_1^2%y)*^:(<y) 1'
+
+ P=:  gsngon 4    NB. regular planar polygon
+ 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=: 294 360 287
+
+ paint=: 3 : 0
+   gsinit GS_LIGHT
+   gsdrawviewbox RED
+   (0.05;YELLOW) gsmark 4{.   Q
+   (0.05;CYAN  ) gsmark 2{.4}.Q
+   gsdrawpolygon P0;(gsnormal P0);RED
+   gsdrawpolygon P1;(gsnormal P1);BLUE
+   gsdrawquadstrip Q;'';GREEN
+   gsfini''
+ )
+
+ NB. ------------------------- TBD in jzopenglutil.ijs ---
+ gsnormal=: (% +/&.(*:"_))@(+/)
+ gsvertnorm=: glVertex [ [EMAIL PROTECTED]
+ gsquadnorms=: (2,:4)&(gsvertnorm;._3)
+
+ gsdrawquadstrip=: 3 : 0 "2
+   'v n c'=. y
+   v=. gscol3 v
+   if. #c do. gscolor c end.
+   glBegin GL_QUAD_STRIP
+   gsquadnorms v
+   glEnd''
+ )
+
+ gsmark=: 0.1&$: : (4 : 0)"1
+   glPushMatrix ''
+   glTranslate y
+   gsdrawcube&>/ 2{.(boxopen x),<SKYBLUE
+   glPopMatrix ''
+ )
+
+
+ ----- Original Message ----
+ From: Brian Schott <[EMAIL PROTECTED]>
+ To: Programming forum <[email protected]>
+ Sent: Saturday, July 29, 2006 12:05:37 PM
+ Subject: Re: [Jprogramming] opengl geometry meshes?
+
+
+ Oleg,
+
+     I altered your script to show the flat sides more
+ clearly. I added the following line to your paint verb
+ below gsinit.
+   glShadeModel GL_FLAT
+ This resulted in more distinct sides, but may not have been
+ what you wanted. I think you can see the result by holding
+ down the right-arrow or up-arrow key and watching the
+ lighting change. I see the most dramatic changes with the
+ right- or left-arrow key movements from the original
+ position.
+
+     I noticed a peculiar feature in the graphic that may
+ be a reult of your model, or may be a "feature" of the J
+ openGL. The feature is that the light shading changes
+ dramatically as soon as you press any scene movement key,
+ such as j, x, or arrow. Whereas initially the forward end of
+ the cylinder is brightly lit, as soon as any key is pressed
+ (while the graphic window is in focus), the same end is NOT
+ lit any longer.
+
+     Btw, I ran your graphic by embedding it in the file
+ /Users/brian/j601/system/examples/graphics/opengl/demo/glviews.ijs
+ . This is done by replacing the 2 characters "XX" in the
+ file by your code.
+
+ (B=)
+
+ On Thu, 27 Jul 2006, Oleg Kobchenko wrote:
+
+ + 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
+ +
+
+ (B=) <----------my "sig"
+
+ Brian Schott
+ Atlanta, GA, USA
+ schott DOT bee are eye eh en AT gee em ae eye el DOT com
+ http://schott.selfip.net/~brian/
+ ----------------------------------------------------------------------
+ For information about J forums see http://www.jsoftware.com/forums.htm
+

(B=) <----------my "sig"

Brian Schott
Atlanta, GA, USA
schott DOT bee are eye eh en AT gee em ae eye el DOT com
http://schott.selfip.net/~brian/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to