Polygon Types - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Polygon Types

Description:

CS1566, Panos K. Chrysanthis University of Pittsburgh. 1. Polygon Types ... int main(int argc, char* argv[]) glutMouseFunc(OnMouse) ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 15
Provided by: panoskchr
Category:
Tags: argv | polygon | types

less

Transcript and Presenter's Notes

Title: Polygon Types


1
Polygon Types
2
Primitives and Attributes
  • Primitives define what (object) to display
  • Attributes determine how an object is display
  • Conceptually attributes are associated with
    objects but in OpenGL are associated with the
    state of drawing.
  • The size of a point glPointSize(Glfloat width)
  • Attributes for a line segments color,
    thickness, and (stipple) pattern
  • void glLineWidth(GLFloat width) default 1.0
    pixel
  • void glLineStipple(Glint factor, GLUshort
    pattern)
  • 1 in pattern means pixel is drawn, 0 means pixel
    is not drawn
  • Factor (1-256) repeats successive groups of 1s
    and 0s in pattern
  • E.g., glLineStipple(2,0xACAC)

3
White Rectangle
  • glBegin(GL_POLYGON)
  • glVertex2f(-0.5, -0.5)
  • glVertex2f(0.5, -0.5)
  • glLineWidth(2.0)
  • glLineStripple(2, 0xCCCC)
  • glVertex2f(0.5, 0.5)
  • glLineWidth(1.0)
  • glLineStripple(1, 0xFFFF)
  • glVertex2f(-0.5, 0.5)
  • glLineWidth(2.0)
  • glLineStripple(2, 0xCCCC)
  • glEnd()

4
White Rectangle?
  • glLineWidth(1.0)
  • glLineStipple(1, 0xFFFF)
  • glBegin(GL_LINES)
  • glVertex2f(-30, -30)
  • glVertex2f(30, -30)
  • glEnd()
  • glLineWidth(2.0)
  • glLineStipple(2, 0xCCCC)
  • glBegin(GL_LINES)
  • glVertex2f(30, -30)
  • glVertex2f(30, 30)
  • glEnd()

glLineWidth(1.0) glLineStipple(1,
0xFFFF) glBegin(GL_LINES) glVertex2f(30,
30) glVertex2f(-30, 30) glEnd()
glLineWidth(2.0) glLineStipple(2,
0xCCCC) glBegin(GL_LINES) glVertex2f(-30,
30) glVertex2f(-30, -30) glEnd()
5
Enabling OpenGL Features
  • It is not sufficient to set the parameters of a
    feature such as stippling, lighting,
    hidden-surface removal etc.
  • Features must be enable and disable using
    void glEnable(GLenum feature) void
    glDisable(Glenum feature)
  • E.g., line stippling is enabled by
  • glEnable(GL_LINE_STIPPLE)

6
Interaction
7
Input Devices
7
  • Physical device types
  • Keyboard devices return character codes
  • Pointing devices indicate or return positions
    on the screen
  • Absolute-positioning
  • Relative-positioning

8
Logical Devices
  • Physical vs. Logical properties
  • Logical characteristics of a device
  • What measurements it returns to the user program
  • When it returns these measurements (device
    trigger)
  • Classification of logical devices
  • String returns a character strings
  • Locator provides a position in world coordinate
  • Pick returns the identifier of an object
  • Choice allows user to select from multiple
    options
  • Dial provides analog input (via, e.g.,
    slidebars)
  • Stroke returns an array of locations

9
Input Modes
  • Modes of obtaining measurements and status of
    devices
  • Request Mode request_locator(deviceID, measure)
  • Event Mode event queues vs. event callback
    functions

10
Event-driven Input
  • Mouse events
  • Window events
  • Keyboard events
  • Display and Idle events

void mouse(int button, int state, int x, int
y) glutMouseFunc(mouse)
void reshape(GLsizei wx, Glsizei
wy) glutReshapeFunc(reshape)
void keyboard(unsigned char key, int x, int
y) glutKeyboardFunc(keyboard)
void myidle(void) glutIdleFunc(display)
void display(void) glutDisplayFunc(display)
11
Mouse callback example
void OnMouse(int button, int state, int x, int
y) if (buttonGLUT_RIGHT_BUTTON
stateGLUT_DOWN) exit(0)
  • int main(int argc, char argv)
  • glutMouseFunc(OnMouse)

12
Keyboard callback example
void normal_keys(unsigned char key,int x,int y)
// all keys with an ASCII code void
special_keys(int keys,int x,int y) // all
keys without an ASCII code (function keys,
arrows, etc.)
  • int main(int argc, char argv)
  • glutKeyboardFunc(normal_keys)
  • glutSpecialFunc(special_keys)

13
Menus
  • Steps for designing a menu
  • Create the menu
  • MenuIDglutCreateMenu(MenuCallBackFunc)
  • Define menu entries
  • glutAddMenuEntry(entry name, EntryID)
  • glutAddSubMenu(entry name, MenuID)
  • Link to a mouse button glutAttachMenu(GLUT_RIGHT
    _BUTTON)
  • Define the callback function
  • void MenuCallBackFunc(int EntryID)

14
Typical Non-interactive Main Program
  • include ltwindows.hgt
  • include ltgl/glut.hgt
  • include ltstdlib.hgt
  • int main(int argc, char argv)
  • glutInit(argc,argv)
  • glutInitDisplayMode(GLUT_RGB GLUT_DOUBLE
    GLUT_DEPTH)
  • glutInitWindowSize(500,500)
  • glutInitWindowPosition(0,0)
  • glutCreateWindow(My White Rectangle")
  • glutDisplayFunc(display)
  • Init() / set up attributes, set up
    viewing /
  • glutMainLoop()
Write a Comment
User Comments (0)
About PowerShow.com