CS 184: Discussion Section 1 Notes
Programming in a Windowed Environment
Topics
Interactive Windows Programming
- Tcl/Tk provides a
system independent windowing interface.
- Togl is a Tk widget
which provides an OpenGL drawing area.
- Dealing with event loops and call backs
- HandleDisplay()
The provided rendering code for HandleDisplay (i.e. within
the comments "// START: ASSIGNMENT 1: Rendering Code" and "// END
: ASSIGNMENT 1: Rendering Code") is sample OpenGl code. You will need
to replace it entirely with your own code; however, if you are
unfamiliar with OpenGl, I would see how the code provided draws stuff
to the window (comment out parts of it and see the change).
- HandleWrite()
The provided code will prompt the user for a file name and
write out a simple square. Try it...right-click and you should get a
'Save As' prompt. You will need to replace the square writing code in
CWindow::WriteSLIDE with your own code.
- HandleMouseButton()
The provided code does not display the mouse events being
captured, but the code to do so is all there - simply set the
"cbDisplayEvents" flag (in window.cxx) to true. Then, when you click
anywhere within the 'slidedraw' window, the events will be shown on the
corresponding console window.
Basic Introduction to OpenGL
OpenGL is the set of Graphics Library routines which we will be
using throughout the semester. There is an on line OpenGL
Reference
Page if you do not have the recommended text.
Things to know to do HW #1:
- Double Buffering
Drawing commands are done to an off screen
memory buffer then the whole buffer is swapped to the front making all
drawing commands visible at once. This swapping of buffers is done by Togl_SwapBuffers().
- glColor3f(float R, float G, float B)
This sets what color will used for any drawing primitives which follow.
- glBegin(GLenum MODE)
glBegin is balanced by a glEnd and will produce
geometry with vertices specified by glVertex2f calls in the
middle. Depending apon which MODE different types of geometry
will be drawn. The different MODES you might want to use are:
- GL_POLYGON
- GL_LINE_LOOP
- GL_LINE_STRIP
- GL_POINTS
- glVertex2f(float X, float Y)
This specifies the coords of a vertex. This should be called in between
calls to glBegin and glEnd.
- glEnd()
This ends the description of a geometric primitive, at which time
another call to glBegin could then happen.
Basic Introduction to SLIDE
# SLIDE Description of a Square
#############################
# Geometry Specification
point p0 ( 0.75 0.75 0 )
endpoint
point p1 ( 0.25 0.75 0 )
endpoint
point p2 ( 0.25 0.25 0 )
endpoint
point p3 ( 0.75 0.25 0 )
endpoint
face fSquare ( p0 p1 p2 p3 )
endface
object oSquare ( fSquare )
solid SLF_HOLLOW
shading SLF_WIRE
endobject
#############################
# Viewing Specification
camera cam
projection SLF_PARALLEL
frustum ( -0.5 -0.5 -2 )
( 0.5 0.5 -0.01 )
endcamera
group gCam
instance cam
id iCam
translate ( 0.5 0.5 1 )
endinstance
endgroup
window win
endwindow
viewport vp win
endviewport
render vp gCam.iCam.cam oSquare
endrender
Other Questions/Issues about HW1
- The data structure used to store geometry is important because it
will be used in both, drawing to the screen and writing to a file. You
can use any data structure you'd like (something like a simple linked
list will work fine), but make sure you are comfortable with the data
structure and you submit everything needed to compile it.
- Compiling the code: The provided project settings assume that you
have an 'S' drive mapped to the SLIDE libraries on your machine. This
is true in the lab computers, but if you are doing the project from
home, you will need to change the project settings to change the 'S:'
to where SLIDE libraries are installed. The installation instructions
talk about this. Please read those carefully. After you compile and
run, you should see a window with some cyan (blue-green) things in it -
this is a good sign: it means you have compiled properly.