2002 by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data:

Slides:



Advertisements
Similar presentations
Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects.
Advertisements

Coordinate System.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
2006 by Jim X. Chen: 1.1. Review –Graphics commands specify straight lines or other geometric primitives that are scan-converted.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Objectives Introduce OpenGL buffers and read/write Introduce OpenGL buffers and read/write Introduce texture mapping Introduce texture mapping Introduce.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Buffers Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Buffers Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
Introduction to OpenGL (Part 3) Ref: OpenGL Programming Guide (The Red Book)
CS 4731: Computer Graphics Lecture 21: Raster Graphics Part 2 Emmanuel Agu.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
 Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.  Applications:
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
Review of OpenGL Basics
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Computer Graphics Bing-Yu Chen National Taiwan University.
Buffers Computer Graphics I, Fall 2010.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
Buffers. 2 Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Chapter 8. Drawing Pixels, Bitmaps, Fonts, and Images Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Buffers Ed Angel Professor Emeritus of Computer Science
Discrete Techniques.
Draw a Simple Object.
Computer Graphics Lecture 32
Computer Graphics Lecture 33
Introduction to Computer Graphics with WebGL
Geb Thomas Adapted from the OpenGL Programming Guide
Class 26 more textures environmental textures Color ramps
Display Lists & Text Glenn G. Chappell
Computer Graphics Buffers
OpenGL program.
Buffers Ed Angel Professor Emeritus of Computer Science
CS297 Graphics with Java and OpenGL
Class 27 more textures environmental textures Color ramps
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Presentation transcript:

by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data: · Bitmaps, typically used for characters in fonts (bilevel) · Image data, which might have been scanned in or calculated (multiple-level)

Fall 2007 revised2 Current Raster Position (CRP) OpenGL maintains raster position, a 3D-position in world coordinate Modified by: –glRasterPos() specify the object coordinates (as in glVertex); transformed by MODELVIEW & PROJECTION, passed to the clipping stage. If the position is not culled, raster position is updated; otherwise, it is not valid. –glBitmap() glGetFloatv(GL_CURRENT_RASTER_POSITION, fptr) to obtain the CRP glGetBooleanv (GL_CURRENT_RASTER_POSITION_VALID, &boolvar) to test validity of CRP

by Jim X. Chen: 3 Bitmaps and Characters The most common use of bitmaps for characters The commands glRasterPos*() and glBitmap() position and draw a single bitmap on the screen. Void glRasterPos{234 }{sifd}{v} (TYPE x, TYPE y, TYPE z, TYPE w); Here (x, y, z, w) are transformed to screen coordinates through the transformation pipeline as an ordinary vertex Void glWindowPos{23}{sifd}{v} (TYPE x, TYPE y, TYPE z, TYPE w); Sets window coordinates

4 A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a rectangular portion of the window Specification: –Width need not be multiples of 8, but specified in hex code –Specified in one dimensional array, row by row, starting from lower-left corner Bitmap and Characters (cont) You can't rotate bitmap fonts because the bitmap is always drawn aligned to the x and y framebuffer axes.

Fall 2007 revised5 Draw a bit map at the current raster position: glBitmap (w, h, xbo, ybo, xbi, ybi, bitmapPtr) –xbo, ybo: origin –xbi, ybi: increment glBitmap(10, 12, 0, 0, 11, 0, bitmapPtr)

by Jim X. Chen: 6 Drawing a Bitmapped Character: drawf.c #include GLubyte rasters[24] = { 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0 }; drawf

by Jim X. Chen: 7 void init(void) { glPixelStorei (GL_UNPACK_ALIGNMENT, 1); // how the data to be unpacked glClearColor (0.0, 0.0, 0.0, 0.0); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glRasterPos2i (20, 20); // the current raster position glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho (0, w, 0, h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); } drawf

by Jim X. Chen: 8 Images an image can contain the complete (R, G, B, A) quadruple stored at each pixel. Images can come from several sources, such as: ·A photograph that’s digitized with a scanner ·Generated on the screen by a graphics program using the graphics hardware and then read back, pixel by pixel ·A software program that generated the image in memory pixel by pixel In addition to simply being displayed on the screen, images can be used for texture maps

by Jim X. Chen: 9 An example void initImage(void) { read_stars_image(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } void drawImage(float x, float y, float z) { glRasterPos3f(x, y, z); glDrawPixels(stars_pixels, stars_pixels, GL_LUMINANCE, GL_UNSIGNED_BYTE, stars_image); } void display(void) { drawImage(-2.4*Width, -2.4*Height, -2.0*Width); drawRobot(A, B, C, alpha, beta, gama); glutSwapBuffers(); } Image

by Jim X. Chen: Reading, Writing, and Copying Pixel Data OpenGL provides three basic commands that manipulate image data: ·glReadPixels() -- Reads a rectangular array of pixels from the framebuffer and stores the data in processor memory. ·glDrawPixels() -- Writes a rectangular array of pixels into the framebuffer from data kept in processor memory. ·glCopyPixels() -- Copies a rectangular array of pixels from one part of the framebuffer to another. Image

Fall 2007 revised11 APIs for Images glReadPixels() –Reading pixel data from framebuffer to processor memory. glDrawPixels() –Writing pixel data from processor memory to framebuffer glCopyPixels() –Copying pixel data within the framebuffer

Fall 2007 revised12 Imaging Pipeline

Fall 2007 revised13 More on glCopyPixels Note that there's no need for a format or data parameter for glCopyPixels(), since the data is never copied into processor memory. The read source buffer and the destination buffer of glCopyPixels() are specified by glReadBuffer() and glDrawBuffer() respectively –Default: single-buffer: GL_FRONT Double-buffered: GL_BACK

by Jim X. Chen: Storing, Transforming, and Mapping Pixels An image stored in memory has between 1 or 4 chunks of data, called elements, for each pixel. The data might consist of just the color index or the luminance, or the RGBA components The possible arrangements of pixel data, or formats, determine the number of elements stored for each pixel and their order. Image data is typically stored in processor memory in rectangular 2-D or 3-D arrays. As image data is transferred from memory into the framebuffer, or from the framebuffer into memory, OpenGL can perform several operations on it.

Fall 2007 revised15 Pixel Format GREY SCALE GREY SCALE with alpha

Fall 2007 revised16 Data Type

Fall 2007 revised17 glPixelStore() –Controlling Pixel-Storage Modes –glPixelStorei(GL_UNPACK_ALIGNMENT, 1); Packing and unpacking refer to the way that pixel data is written to and read from processor memory. tells OpenGL not to skip bytes at the end of a row Pixel Storage Modes

by Jim X. Chen: Controlling Pixel-Storage Modes void glPixelStore{if}(GLenum pname, TYPE param) Sets the pixel-storage modes The GL_UNPACK* parameters control how data is unpacked from memory into framebuffer; The GL_PACK* parameters control how data is packed into memory. Parameter NameTypeInitial ValueValid Range GL_UNPACK_SWAP_BYTES, GL_PACK_SWAP_BYTESGLbooleanFALSETRUE/FALSE GL_UNPACK_LSB_FIRST, GL_PACK_LSB_FIRSTGLbooleanFALSETRUE/FALSE GL_UNPACK_ROW_LENGTH, GL_PACK_ROW_LENGTHGLint0any nonnegative integer GL_UNPACK_SKIP_ROWS, GL_PACK_SKIP_ROWSGLint0any nonnegative integer GL_UNPACK_SKIP_PIXELS, GL_PACK_SKIP_PIXELSGLint0any nonnegative integer GL_UNPACK_ALIGNMENT, GL_PACK_ALIGNMENTGLint41, 2, 4, 8

Fall 2007 revised19 PixelStorei(GL_UNPACK_ALIGNMENT, x) Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are: –1 (byte-alignment), –2 (rows aligned to even-numbered bytes), –4 (word-alignment [default]), and –8 (rows start on double-word boundaries). Byte:8-bit Word:16-bit Double-word:32-bit Byte:8-bit Word:16-bit Double-word:32-bit

Fall 2007 revised20 Details 1st row 2nd row 1st row 2nd row Client memory Byte aligned (1) Word aligned (4) The start of each row of pixels is … w=3,h=2 Assuming the image is of size 3x2:

Fall 2007 revised21 Settings For RGBA images, it doesn’t matter (each pixel has 4 bytes: RGBARGBA…) For RGB and luminance images, it should be set to byte-aligned (data are densely packed) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glPixelStorei(GL_UNPACK_ALIGNMENT, 4)

by Jim X. Chen: Parameter NameTypeInitial ValueValid Range GL_UNPACK_ROW_LENGTH, GL_PACK_ROW_LENGTHGLint0any nonnegative integer GL_UNPACK_SKIP_ROWS, GL_PACK_SKIP_ROWSGLint0any nonnegative integer GL_UNPACK_SKIP_PIXELS, GL_PACK_SKIP_PIXELSGLint0any nonnegative integer GL_UNPACK_ALIGNMENT, GL_PACK_ALIGNMENTGLint41, 2, 4, 8

by Jim X. Chen: Pixel-Transfer Operations You can perform various operations on pixels as they’re transferred from and to the framebuffer: glPixelTransfer{if}(GLenum pname, TYPEparam); Pixel Mapping All the color components, color indices, and stencil indices can be modified by means of a table lookup to map to different values/ranges Magnifying, Reducing, or Flipping an Image Normally, each pixel in an image is written to a single pixel on the screen. However, you can arbitrarily magnify or reduce an image by using glPixelZoom().

Fall 2007 revised24 Improving Pixel Pipeline Performance A series of fragment operations is applied to pixels as they are drawn into the framebuffer. For optimum performance, disable all fragment operations. While performing pixel operations, disable other costly states, such as texturing and lighting It is usually faster to draw a large pixel rectangle than to draw several small ones, since the cost of transferring the pixel data can be amortized over many pixels