Buffers 91.427 Computer Graphics I, Fall 2010.

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
Graphics Pipeline.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Objectives Introduce OpenGL buffers and read/write Introduce OpenGL buffers and read/write Introduce texture mapping Introduce texture mapping Introduce.
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
Introduction to OpenGL (Part 3) Ref: OpenGL Programming Guide (The Red Book)
CS 4731: Computer Graphics Lecture 21: Raster Graphics Part 2 Emmanuel Agu.
Introduction to Computer Graphics
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
Components Text Text--Processing Software A Word Processor is a software application that provides the user with the tools to create and edit text.
CSE (Notre Dame) Computer Graphics Lecture 16 A Simple Draw Image Example More Texture Mapping Simple OpenGL Image Library (SOIL) Transparency &
WEB GRAPHICS. The Pixel Computer displays are comprised of rows and columns of pixels. Pixels are indivisible. Some common screen resolutions are:, 600.
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
 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.
Chapter 2 Getting Started: Drawing Figures. The Framebuffer Lecture 2 Fri, Aug 29, 2003.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 8: Texture Mapping.
2002 by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data:
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
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.
Lecture 4 Pixels, Images and Image Files 1. In this Lecture, you will learn the following concepts: Image files (in particular, the BMP file format) How.
Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
Demetriou/Loizidou – ACSC 345 – Chapter 7 Discrete Techniques Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science Frederick Institute.
Chapter 8: Discrete Techniques Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
1 Chapter 7 Discrete Techniques. 2 Buffer Define a buffer by its spatial resolution (n x m) and its depth k, the number of bits/pixel pixel.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Discrete Techniques Chapter 7 Begun February 22, 2005 Finished April 26, 2005.
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic Light Source.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Discrete Techniques Chapter 7.
Buffers, Compositing and Blending Week 8 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New.
Buffers. 2 Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending.
Computer Graphics I, Fall 2010 Building Models.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
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.
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Buffers Ed Angel Professor Emeritus of Computer Science
Discrete Techniques.
Draw a Simple Object.
Better Interactive Programs
Discrete Techniques Chapter 8.
Introduction to Computer Graphics with WebGL
Discrete Techniques Chapter 8.
Advanced Menuing, Introduction to Picking
Introduction to Computer Graphics with WebGL
Geb Thomas Adapted from the OpenGL Programming Guide
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Class 26 more textures environmental textures Color ramps
Better Interactive Programs
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Computer Graphics Buffers
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Buffers Ed Angel Professor Emeritus of Computer Science
Class 27 more textures environmental textures Color ramps
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Presentation transcript:

Buffers 91.427 Computer Graphics I, Fall 2010

Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending 91.427 Computer Graphics I, Fall 2010

Buffer Define buffer by spatial resolution (n x m) and depth (or precision) k = # bits/pixel pixel 91.427 Computer Graphics I, Fall 2010

OpenGL Frame Buffer 91.427 Computer Graphics I, Fall 2010

OpenGL Buffers Color buffers can be displayed Depth Accumulation Front Back Auxiliary Overlay Depth Accumulation High resolution buffer Stencil Holds masks 91.427 Computer Graphics I, Fall 2010

Writing in Buffers Conceptually, can consider all of memory as large 2-d array of pixels Read and write rectangular block of pixels Bit block transfer (bitblt) operations Frame buffer is part of this memory memory source frame buffer (destination) writing into frame buffer 91.427 Computer Graphics I, Fall 2010

Writing Model Read destination pixel before writing source 91.427 Computer Graphics I, Fall 2010

Bit Writing Modes Source and destination bits combined bitwise 16 possible functions (one per column in table) XOR replace OR 91.427 Computer Graphics I, Fall 2010

XOR mode Recall from Chapter 3 can use XOR by enabling logic operations and selecting XOR write mode XOR especially useful for swapping blocks of memory such as menus stored off screen If S = screen and M = menu ==> sequence S  S  M M  S  M swaps S and M 91.427 Computer Graphics I, Fall 2010

The Pixel Pipeline OpenGL has separate pipeline for pixels Writing pixels involves Moving pixels from processor memory to frame buffer Format conversions Mapping, Lookups, Tests Reading pixels Format conversion 91.427 Computer Graphics I, Fall 2010

Raster Position OpenGL maintains raster position as part of state Set by glRasterPos*() glRasterPos3f(x, y, z); raster position = geometric entity Passes through geometric pipeline Eventually yields 2D position in screen coordinates This position in frame buffer is where next raster primitive drawn 91.427 Computer Graphics I, Fall 2010

Buffer Selection OpenGL can draw into or read from any of color buffers (front, back, auxiliary) Default to back buffer Change with glDrawBuffer and glReadBuffer Note that format of pixels in frame buffer is different from that of processor memory and these two types of memory reside in different places Need packing and unpacking Drawing and reading can be slow 91.427 Computer Graphics I, Fall 2010

Bitmaps OpenGL treats 1-bit pixels (bitmaps) differently from multi-bit pixels (pixelmaps) Bitmaps = masks that determine if = corresponding pixel in = frame buffer is drawn with = present raster color 0  color unchanged 1  color changed based on writing mode Bitmaps = useful for raster text GLUT font: GLUT_BIT_MAP_8_BY_13 91.427 Computer Graphics I, Fall 2010

Raster Color Same as drawing color set by glColor*() Fixed by last call to glRasterPos*() Geometry drawn in blue Ones in bitmap use drawing color of red glColor3f(1.0, 0.0, 0.0); glRasterPos3f(x, y, z); glColor3f(0.0, 0.0, 1.0); glBitmap(……. glBegin(GL_LINES); glVertex3f(…..) 91.427 Computer Graphics I, Fall 2010

Drawing Bitmaps offset from raster position increments in raster glBitmap(width, height, x0, y0, xi, yi, bitmap) offset from raster position increments in raster position after bitmap drawn first raster position second raster position 91.427 Computer Graphics I, Fall 2010

Example: Checker Board GLubyte wb[2] = {0 x 00, 0 x ff}; GLubyte check[512]; int i, j; for(i=0; i<64; i++) for (j=0; j<64, j++) check[i*8+j] = wb[(i/8+j)%2]; glBitmap( 64, 64, 0.0, 0.0, 0.0, 0.0, check); 91.427 Computer Graphics I, Fall 2010

Pixel Maps OpenGL works with rectangular arrays of pixels called pixel maps or images Pixels are in one byte ( 8 bit) chunks Luminance (gray scale) images 1 byte/pixel RGB 3 bytes/pixel Three functions Draw pixels: processor memory to frame buffer Read pixels: frame buffer to processor memory Copy pixels: frame buffer to frame buffer 91.427 Computer Graphics I, Fall 2010

OpenGL Pixel Functions glReadPixels(x,y,width,height,format,type,myimage) size type of pixels start pixel in frame buffer type of image pointer to processor memory GLubyte myimage[512][512][3]; glReadPixels(0,0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, myimage); glDrawPixels(width,height,format,type,myimage) starts at raster position 91.427 Computer Graphics I, Fall 2010

Image Formats Often work with images in standard format (JPEG, TIFF, GIF) How read/write such images with OpenGL? No support in OpenGL OpenGL knows nothing of image formats Some code available on Web Can write readers/writers for some simple formats in OpenGL 91.427 Computer Graphics I, Fall 2010

Displaying a PPM Image PPM = very simple format Each image file consists of header followed by all pixel data Header P3 # comment 1 # comment 2 . #comment n rows columns maxvalue pixels 91.427 Computer Graphics I, Fall 2010

Reading the Header check for “P3” in first line FILE *fd; int k, nm; char c; int i; char b[100]; float s; int red, green, blue; printf("enter file name\n"); scanf("%s", b); fd = fopen(b, "r"); fscanf(fd,"%[^\n] ",b); if(b[0]!='P'|| b[1] != '3'){ printf("%s is not a PPM file!\n", b); exit(0); } printf("%s is a PPM file\n",b); check for “P3” in first line 91.427 Computer Graphics I, Fall 2010

Reading the Header (cont) fscanf(fd, "%c",&c); while(c == '#') { fscanf(fd, "%[^\n] ", b); printf("%s\n",b); } ungetc(c,fd); skip over comments by looking for # in first column 91.427 Computer Graphics I, Fall 2010

Reading the Data scale factor fscanf(fd, "%d %d %d", &n, &m, &k); printf("%d rows %d columns max value= %d\n",n,m,k); nm = n*m; image=malloc(3*sizeof(GLuint)*nm); s=255./k; for(i=0;i<nm;i++) { fscanf(fd,"%d %d %d",&red, &green, &blue ); image[3*nm-3*i-3]=red; image[3*nm-3*i-2]=green; image[3*nm-3*i-1]=blue; } scale factor 91.427 Computer Graphics I, Fall 2010

Scaling the Image Data Can scale image in pipeline glPixelTransferf(GL_RED_SCALE, s); glPixelTransferf(GL_GREEN_SCALE, s); glPixelTransferf(GL_BLUE_SCALE, s); May have to swap bytes when go from processor memory to frame buffer depending on processor If so, can use glPixelStorei(GL_UNPACK_SWAP_BYTES,GL_TRUE); 91.427 Computer Graphics I, Fall 2010

The display callback void display() { glClear(GL_COLOR_BUFFER_BIT); glRasterPos2i(0,0); glDrawPixels(n,m,GL_RGB, GL_UNSIGNED_INT, image); glFlush(); } 91.427 Computer Graphics I, Fall 2010