glut ps pi alls
play

GLUT&ps+pi+alls alexandrizavodny GLUTbarebones - PowerPoint PPT Presentation

GLUT&ps+pi+alls alexandrizavodny GLUTbarebones WhatisthesimplestGLUTappyoucanwrite? GLUTbarebones GLUTbarebones GLUTbarebones


  1. GLUT
&ps
+
pi+alls
 alexandri
zavodny


  2. GLUT
barebones
 What
is
the
simplest
GLUT
app
you
can
write?


  3. GLUT
barebones


  4. GLUT
barebones


  5. GLUT
barebones
 What
is
the
simplest
GLUT
app
you’d
WANT
to
write?


  6. GLUT
barebones
 • What
is
the
simplest
GLUT
app
you’d
WANT
to
write?
 • Leave
nothing
to
fate:
 – Set
the
window
size
+
default
posi&on
 – Set
the
projec&on
and
modelview
matrices
 – Set
the
object’s
color
 – Request
double
buffering,
depth
buffer,

RGBA
color
buffer
 – Make
sure
that
depth
tes&ng
is
on
(GL_DEPTH_TEST)
 – Clear
the
color
buffer
/
depth
buffer!
 – Swap
the
buffers
/
flush
to
buffer 


  7. GLUT
barebones
 • Not
much
longer:


  8. Matrix
Maintenance
 • Keep
track
of
your
GL_PROJECTION
and
 GL_MODELVIEW
matrices!
 – glLoadIden&ty()
when
appropriate
 • Know
your
mode
/
pick
a
conven&on
 – Single
projec&on:
update
in
resize
callback
and
 forget
about
it!
 – Mul&
projec&on:
update
every
frame!


  9. Matrix
Maintenance
 • glOrtho
/
gluOrtho2D
 • glTranslate
/
glRotate
/
glScale
 • glFrustum
 • gluPerspec&ve
 • gluLookAt


  10. Matrix
Maintenance
 • Know
which
func&ons
are
appropriate
 • GL_PROJECTION
 – glOrtho
/
gluOrtho2D
 – gluPerspec&ve
 – glFrustum
 • GL_MODELVIEW
 – gluLookAt
 – glTranslate
/
glRotate
/
glScale


  11. Display
Lists
 • Why?
 – Efficiency.
 • Why
not?
 – Too
sta&c.
 • How?
 – GLuint
displaylist
=
glGenLists(1);
 – glNewList(displaylist,
GL_COMPILE);
 • //
drawing
code
 – glEndList();



  12. Ligh&ng
Checklist
 • To
get
ligh&ng:
 – 1)
Ligh&ng
must
be
enabled
 – 2)
Objects
must
have
materials
 • 2a)
Set
material
proper&es
with
glMaterial*()
 • 2b)
Override
material
proper&es
and
use
glColor()
 – 3)
Objects
must
have
normals!
 • All
GLUT
primi&ves
and
GLU
quadrics
have
them
yay
 • If
you
use
glScale,
use
glEnable(GL_NORMALIZE)!


  13. Ligh&ng
Checklist
(cont’d)
 • Step
1:
Enabling
ligh&ng
 – glEnable(GL_LIGHTING);
 • But
there
are
no
lights,
so…
 – glEnable(GL_LIGHT0); 
 
//or
1,
2,
…
up
to
7*
 • And
that
light
has
no
proper&es,
so…
 – glLigh+v(GL_LIGHT0,
GL_POSITION,
posi&on);
 – glLigh+v(GL_LIGHT0,
GL_DIFFUSE,
diffuseColor);
 – glLigh+v(GL_LIGHT0,
GL_AMBIENT,
ambientColor);
 *Some
versions
of
OpenGL
have
fewer!


  14. Ligh&ng
Checklist
(cont’d)
 • Step
2:

Use
materials
or
setup
color
tracking
 – If
using
materials:
 • glColor
won’t
do
anything
;
use
glMaterialfv()
instead
 • Example:
 – Glfloat
red[]
=
{1,
0,
0,
1};
 – glMaterialfv(GL_FRONT_AND_BACK,

 
 
 
 
 

 
 
 
 
GL_AMBIENT_AND_DIFFUSE,
red);
 – If
using
color
tracking:
 • glEnable(GL_COLOR_MATERIAL);
 • glColorMaterial(GL_FRONT,

 
 
 
 
 

 
 
 
 
 
 












GL_AMBIENT_AND_DIFFUSE);


  15. Ligh&ng
Checklist
(cont’d)
 • Step
3:
Normals
 – GLUT
primi&ves
&
GLU
quadrics
have
them
 – Inside
of
GL_QUADS,
GL_TRIANGLES,
etc.:
 • Call
glNormal3f(nx,
ny,
nz)
before
each
glVertex3f.
 • Step
4:
PROFIT


  16. Misc
Ligh&ng
Tips
 • When
using
glMaterialfv
or
glLigh+v,
make
 sure
your
arrays
have
4
elements!!
 – For
light
posi&on,
the
last
component
should
be
1
 • Light
posi&on
gets
transformed
by
the
 modelview
matrix
just
like
a
vertex!


  17. Misc.
Tips
 • Follow
protocol!
 • Create
a
“debug
mode”
that
draws:
 – A
grid
over
the
ground
plane
 – The
axes,
showing
+/‐
XYZ
direc&ons


  18. Misc.
Tips
 • All
of
the
gl*
func&ons
allow
you
to
 set…
 glGet()
allows
you
to
get
info
back!
 – Check
if
state
variables
are
enabled
/
disabled
 – Great
for
debugging
 • glGetError()
returns
OpenGL‐specific
‘errno’
 • Sketch
out
your
app
ahead
of
&me!


Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend