Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Conceptual Graphics Framework - Introduction to Computer Graphics - Lecture Slides, Slides of Computer Graphics

In Introduction to Computer Graphics course we study the basic concept of the principle of computer architecture. In these lecture slides the key points are:Conceptual Graphics Framework, Graphics Library, Graphics Card, Immediate-Mode Fixed-Function Mode, State Machine, State Variables, Pseudo Code, Color and Shape, Pros and Cons, Bundles and Unsets, Local Variables

Typology: Slides

2012/2013

Uploaded on 04/23/2013

sarasvan
sarasvan 🇮🇳

4.4

(20)

120 documents

1 / 53

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 05:
OpenGL 2 (Fixed-Function)
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35

Partial preview of the text

Download Conceptual Graphics Framework - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Lecture 05:

OpenGL 2 (Fixed-Function)

Remember…

• Conceptual Graphics Framework

• Graphics Library can be Direct3D, Java3D, OpenGL, etc.

• It is a software API that controls the functions of a

piece of hardware – the graphics card.

Graphics System/ GPU Application Model/data base

Software Hardware

Application

program

Graphics

Library

State Variables

• Pseudo code:

SetState (LineStyle, DASHED);

SetState (LineColor, RED);

DrawLine ( PtStart = (x1,y1), PtEnd = (x2,y2) );

SetState (LineColor, BLUE);

DrawLine ( PtStart = (x2,y2), PtEnd = (x3,y3) );

SetState (LineStyle, SOLID);

DrawLine ( PtStart = (x3,y3), PtEnd = (x4,y4) );

What color and shape?

What color and shape?

What color and shape?

State Variables

• Pseudo code:

SetState (LineStyle, DASHED);

SetState (LineColor, RED);

DrawLine ( PtStart = (x1,y1), PtEnd = (x2,y2) );

SetState (LineStyle, DASHED);

SetState (LineColor, BLUE);

DrawLine ( PtStart = (x2,y2), PtEnd = (x3,y3) );

SetState (LineStyle, SOLID);

SetState (LineColor, BLUE);

DrawLine ( PtStart = (x3,y3), PtEnd = (x4,y4) );

What color and shape?

What color and shape?

What color and shape?

State Variables – Pros and Cons

• What if…?

function DrawDashedTriangle (pt1,pt2,p3) {

SetState( LineStyle, DASHED );

DrawLine( PtStart=pt1, PtStart=p2 );

DrawLine( PtStart=pt2, PtStart=p3 );

DrawLine( PtStart=pt3, PtStart=p1 );

• What color is the triangle?

– Pros: trickle down effect, caller can control the

subroutine’s behavior

– Cons: the color is undefined! Who set my color?!

State Variables – Pros and Cons

• What’s right and what’s wrong with this?

function DrawTriangle (pt1,pt2,p3,

int origColor, int curColor,

int origStyle, int curStyle ) {

SetState( LineStyle, curStyle );

SetState(LineColor, curColor);

DrawLine( PtStart=pt1, PtStart=p2 );

DrawLine( PtStart=pt2, PtStart=p3 );

DrawLine( PtStart=pt3, PtStart=p1 );

SetState( LineStyle, origStyle );

SetState(LineColor, origColor);

}

Forgetting the State?

• What if I forget to set some state?

DrawLine ( PtStart = (x1,y1), PtEnd = (x2,y2) );

• What if I set the wrong state?

SetState(LineStyle, 12345);

DrawLine( PtStart=pt1, PtStart=p2 );

• What if I forget the state a variable is in?

Forgetting the State?

  • What if I forget to set some state?

DrawLine ( PtStart = (x1,y1), PtEnd = (x2,y2) );

  • OpenGL provides some good default values. For example, for color, it’s set to (1,1,1,1) – non transparent white
  • How do I know if something worked?

SetState(LineStyle, 12345); DrawLine( PtStart=pt1, PtStart=p2 );

  • You don’t. Since it’s not clear if some configuration of states will send OpenGL spinning, if you suspect an error from OpenGL, call Glenum glGetError(void)
  • What if I forget the state a variable is in?
  • You should use this sparingly… But you can use void glGetBooleanv(Glenum paraname, Glboolean* params) void glGetFixedv(Glenum paraname, Glfixed* params) void glGetFloatv(Glenum paraname, Glfloat* params) void glGetIntegerv(Glenum paraname, Glint* params)

For Example

• How many parameters do you have to pass to render an

object?

void render () {

obj1->drawSelf(myMouse, myScreenSize, myTimer, ...);

obj2->drawSelf(myMouse, myScreenSize, myTimer, ...);

obj3->drawSelf(myMouse, myScreenSize, myTimer, ...);

• How do you enforce that there is only one instance of

myMouse, myScreenSize, myTimer in code?

Possible Answers?

1. Use global variables

2. Use mutual references. For example:

void setChild (CWidget* child)

{

myChild = child; child->setParent(this);

}

MyMouse* getMouse() {

return myMouse;

}

void setParent (PWidget* parent) { myParent = parent; }

void doStuff () { MyMouse mouse = myParent->getMouse(); doStuffWithMouse (mouse); }

Programming Strategies?

• What do you think is the best way to deal with

the state machine and maintain state variables?

– How to access local variables (that correspond to state

variables)?

– Efficiency considerations?

• How do you think the programming with a state

machine affects multi-threaded applications?

Multi-Threading and OpenGL

Thread A

void drawRedDashedTriangle()

pushAttributes();

setColor (RED);

setStyle (DASHED);

drawLine (pt1+d, pt2+d);

drawLine (pt2+d, pt3+d);

drawLine (pt3+d, pt1+d);

d++;

popAttributes();

Thread B

void drawBlueSolidTriangle()

pushAttributes();

setColor (BLUE);

setStyle (SOLID);

drawLine (pt4-p, pt5-p);

drawLine (pt5-p, pt6-p);

drawLine (pt6-p, pt4-p);

p--;

popAttributes();

Typical OpenGL Application

Example

• Here we use GLUT, which is a basic GL window

implementation that is on all platforms.

• Pros: cross-platform, command line, easy to use

• Cons: no GUI support (no buttons, menus, etc.)