COMP136: Introduction to Computer Graphics

COMP136: Introduction to Computer Graphics

CAP4730: Computational Structures in Computer Graphics Introduction to OpenGL What is OpenGL?

A software interface to graphics hardware Written in C (NOT C++) Very fast (a standard to be accelerated) Portable Open standard Was SGIs IRIS GL What it isnt A modeling tool A new language

Other options: Direct3D MesaGL VirtualGL (Older) Glide Why would you use one over another? What are companies motivations?

OpenGL/GLU/GLUT/GLUI OpenGL v2.1 (latest) is the core library that is platform independent GLUT v3.7 is an auxiliary library that handles window creation, OS system calls (mouse buttons, movement, keyboard, etc), callbacks. GLU is an auxiliary library that handles a variety of graphics accessory functions ZIP file Look at ZIP file

Headers and Linking OpenGL - main stuff (the only thing that is required) #include Link opengl32.lib (PC) opengl.lib is an SGI implementation opengl32.lib is a Microsoft implementation (what you want) GLU - auxillary functions #include Link glu32.lib (PC)

Headers and Libraries GLUT - Window management (requires download of library) #include Link glut32.lib (PC), or -lglut (UNIX) Instead of GLUT, you can use GLX or WGL GLUT GLUT is a Window Manager Makes it easy to create windows Platform independent Gets you up and running, though it isnt

extremely customizable Not meant for commercial products Lets compare what you get and you dont get from GLUT. Approach to programming in GL Use old code again! If you have any questions, check the Red Book (explains OpenGL) or the Blue Book (reference for commands) Use the function glGetError() to check for errors

Note about function names: gl means OpenGL (glVertex) glu means GLU (gluPerspective) glut means GLUT (glutCreateWindow) Different Parts of a GL Program In your main(), setup GL and GLUT stuff Callbacks Function that gets called when certain events (like a keyboard or mouse event) occur Display

Function where you would put all your graphics routines Global variables and states State Machine Things have a global state till you change it. For example, if you enable depth buffering, it will be on till you disable it. Double Buffer Graphics card scans out the image on the frame buffer. What rate is this done at?

So what is the problem with this? You might be in the middle of drawing a frame when it decides to scan out the image What is a solution? Have two separate frame buffers, one that the card scans out of, and the other you draw into. When you are done drawing a frame, you switch their roles What are the memory requirements? Double Buffering ... glVertex3f(0.1,0.1,0.1)

glutSwapBuffers(); ... Double Buffering ... glVertex3f(0.1,0.1,0.1) glutSwapBuffers(); ... Basic GL Commands glEnable/glDisable GL has many states of operation, and the way

you change them is through Enabling and Disabling them. Ex. glEnable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); Geometry Commands

glBegin glVertex glColor glNormal glTexCoord glEnd Lighting glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0); Glfloat fLightPosition[3]; fLightPosition[0]=1; fLightPosition[1]=1; fLightPosition[2]=1; glLightfv(GL_LIGHT0,GL_POSITION,fLightPosition); Example glBegin(GL_TRIANGLES); glVertex3f(0,1,0); glVertex3f(0,0,1); glVertex3f(0,0,0);

glEnd(); glEnable(GL_LIGHTING); glBegin(GL_TRIANGLES); glVertex3f(0,0,1); glVertex3f(1,0,0); glVertex3f(0,0,0); glEnd(); glDisable(GL_LIGHTING); State Machine OpenGL has several global variables:


They are the current values till changed State Examples

glBegin(GL_TRIANGLES); glColor4f(1.0, 1.0, 1.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glColor4f(1.0, 0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 1.0); glEnd(); Stack Transformations are based on a stack architecture. glVertex3f(1,0,0); glTranslatef(2,0,0);

glVertex3f(1,0,0); glRotatef(90,1,0,0); glTranslatef(2,0,0); glVertex3f(1,0,0); Stack glRotatef(27,.71,.71,0); glPushMatrix(); glPushMatrix(); glTranslatef(-2,-1,1.2);

glScalef(1.5,1.5,1.5); glRotatef(45,0,0,1); glTranslatef(1,0.8,2.4); Stack glTranslatef(0.1, 0.5, 0.5); DrawTorso(); glPushMatrix(); glTranslatef(0.4, 0.4, 0.8); glRotatef(fArmRotation,0,0,1); glDrawUpperArm(); glTranslatef(0,0,-1);

glRotatef(fLowerArmRotation,0.2,0.2,0.7); glPopMatrix();

Recently Viewed Presentations

  • Headline - University of Colorado

    Headline - University of Colorado

    PRCs contain all historical student class and grade information from the University's founding until 1988. ... FAO = Faculty Affairs Office. FIN = Finance. GSS = Graduate Student Services. HON = Honor Code. ... ICS - Basic Student Info. Keyword...
  • Code to Enhance Learning Lesson 1 Maze Objective:

    Code to Enhance Learning Lesson 1 Maze Objective:

    Code to Enhance Learning. Lesson . 1. Maze. Objective: We will be able to sequence instructions to create algorithmto move Papu out of the maze. Objective: We will be able to . sequence. instructions. to create . algorithm. to move...
  • Understanding Our Environment

    Understanding Our Environment

    Periderm - in woody plants only Periderm with lenticel Lenticels - Secretory Cells and Tissue Function Flower nectar Citrus oils Latex Resins Review Organs and Tissues Meristematic Tissues Apical Meristems Lateral Meristems Intercalary Meristems Tissues Produced by Meristems Simple Tissues...
  • Ratios, Proportions, and the Geometric Mean

    Ratios, Proportions, and the Geometric Mean

    Ratios, Proportions, and the Geometric Mean Chapter 6.1: Similarity Ratios A ratio is a comparison of two numbers expressed by a fraction. The ratio of a to b can be written 3 ways: a:b a to b Equivalent Ratios Equivalent...
  • Maternal physiology during pregnancy

    Maternal physiology during pregnancy

    Production of thyroid hormone increases by 40% to 100% to meet maternal and fetal demands. The thyroid gland undergoes moderate enlargement during pregnancy . Circulating thyroid hormone exists in two primary active forms: thyroxine (T4) and triiodothyronine (T3).
  • Essay Writing Toolkit Made by Mike Gershon

    Essay Writing Toolkit Made by Mike Gershon [email protected]

    Title: PowerPoint Presentation Author: Gershon Last modified by: Joel Created Date: 11/21/2011 4:49:25 PM Document presentation format: On-screen Show (4:3)
  • Chapter 3 Exploration and Colonization 1492-1675 An Era

    Chapter 3 Exploration and Colonization 1492-1675 An Era

    By 1511 Spain had conquered Puerto Rico, Jamaica, and Cuba . ... Encounters of people in the Eastern and Western Hemisphere sparked a global market for trade and ideas. This exchange became known as the Columbian Exchange. Items that were...
  • What does it mean to be an Army Professional?

    What does it mean to be an Army Professional?

    The Army Profession. A unique vocation of experts certified in the design, generation, support, and ethical application of landpower, serving under civilian authority, entrusted to defend the Constitution and the rights and interests of the American people.