lab 1: opengl tutorial

Post on 23-Feb-2016

62 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Lab 1: OpenGL Tutorial. CS 282. What’s the plan for today?. Go over our framework code. Learn some basic OpenGL! Reveal Lab 1 Answer questions. Framework Environment. C/C++ and OpenGL Code will be given with Makefiles You can compile in Linux, Mac, and Windows! - PowerPoint PPT Presentation

TRANSCRIPT

Lab 1: OpenGL Tutorial

CS 282

What’s the plan for today?

Go over our framework code.Learn some basic OpenGL!Reveal Lab 1Answer questions

Framework EnvironmentC/C++ and OpenGLCode will be given with Makefiles

You can compile in Linux, Mac, and Windows!You must use the framework

What should you know?At the very least

You’ve programmed beforeYou know the programming cycle

Better for you ifYou are familiar with C/C++

Amazing ifYou already know OpenGLHave a degree in Computer Science

FrameworkWhere do I get it?!

Resources in Class WebsiteThis lab’s framework provides you with

An initial OpenGL windowCallback functions you will need

What is OpenGL?A powerful, open source graphics library

Widely used in both industry and academiaCapable of rendering 3D geometries with a plethora of effects

Keeps a “global” stateTransformation, projection matricesAttributes from primitives

Exercise: CompilingCompile the frameworkChange window size, position, and title

Exercise: Drawing Things!

Since you guys are now pros, let’s draw things!Every GL primitive starts with glBegin(…), and ends with glEnd ()Example:glBegin (GL_POINT);glVertex3f( 1.0,1.0,1.0);glEnd()

Exercise: Drawing QuadsFind the DrawGLScene() function

After glLoadIdentity(), create a GL primitiveusing GL_QUADS

Exercise: Drawing QuadsAdd this code

And this code…

What just happened?!OK, that’s weird, why is the screen yellow?We’ve basically rendered our object too close for us to really see it. So, we need to move (or translate) it further back.

Translation and RotationRotation (unsurprisingly) rotates the primitive,BUT rotates it around the “world” axis, NOT itslocal axis

Hint: You can think of the camera as always being at the world origin(0,0,0)

Translation “moves” the primitive around to adifferent locationThe order you do translations and rotations in MATTERS

Translation and RotationRotate

Translate

Translation and RotationRotate then Translate

Translate then Rotate

Translation and Rotation

WARNING!!! OpenGL will perform translations and rotations IN THE OPPOSITE ORDER YOU WRITE THEM IN CODEi.e. writing the following in code: … glTranslate(...) glRotate(…) …Will rotate then translate the primitive

Translation and RotationImportant things to keep in mind:

Translate/Rotate operates relative to the world originThe order of translations and rotations mattersOpenGL will perform translations and rotations in the OPPOSITE order you list them in code

Exercise: Finish the cubeAdd this line of code above your primitive in your drawing function.

Finish the rest of the cube.Change the color of each side to something else!

glColor3f( red, green, blue );

CallbacksGLUT allows us to interface between events (such as clicking, keyboard input, etc.) and OpenGL.

Lab 1Implement a camera to move around in OpenGL.Use the callback functions provided for you.Use the cube as a way to debug your camera.Make sure you at least create a vector, camera, and framework class.

Questions?

Useful sitesOpenGL Reference Pages: http://www.opengl.org/sdk/docs/man/ (what we use)http://www.opengl.org/sdk/docs/man4/ (latest ver.)NeHe Tutorials (under Legacy Tutorials):http://nehe.gamedev.net/

Note: As of Aug. 2011, the current tutorials are a little out-of-date/deprecated, but in the process of being updated. They still give a good explanation of the basics, but don’t expect to be able to run the code.

top related