Lecture 07: Buffers and Textures

Similar documents
Texture Mapping. Mike Bailey.

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

CS212. OpenGL Texture Mapping and Related

CS 432 Interactive Computer Graphics

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

CT5510: Computer Graphics. Texture Mapping

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

Texturas. Objectives. ! Introduce Mapping Methods. ! Consider two basic strategies. Computação Gráfica

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2)

Assignment #5: Scalar Field Visualization 3D: Direct Volume Rendering

Cap. 3 Textures. Mestrado em Engenharia Informática (6931) 1º ano, 1º semestre

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Discussion 3. PPM loading Texture rendering in OpenGL

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

OpenCL / OpenGL Texture Interoperability: An Image Blurring Case Study

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Computer Graphics. Bing-Yu Chen National Taiwan University

Texture Mapping and Sampling

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒

Grafica Computazionale

CMSC 425: Lecture 12 Texture Mapping Thursday, Mar 14, 2013

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

CS452/552; EE465/505. Texture Mapping in WebGL

Shading/Texturing. Dr. Scott Schaefer

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

Lecture 5 3D graphics part 3

Lighting and Texturing

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

CSE 167: Introduction to Computer Graphics Lecture #9: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

ก ก ก.

+ = Texturing: Glue n-dimensional images onto geometrical objects. Texturing. Texture magnification. Texture coordinates. Bilinear interpolation

Computational Strategies

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

INF3320 Computer Graphics and Discrete Geometry

CSE 167: Lecture 11: Textures 2. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University

Imaging and Raster Primitives

Texture Mapping and Special Effects

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Texture mapping. Computer Graphics CSE 167 Lecture 9

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

Introduction to OpenGL

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

QUESTION 1 [10] 2 COS340-A October/November 2009

-=Catmull's Texturing=1974. Part I of Texturing

Texture Mapping 1/34

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

Most device that are used to produce images are. dots (pixels) to display the image. This includes CRT monitors, LCDs, laser and dot-matrix

Texture Mapping. Texture Mapping. Map textures to surfaces. Trompe L Oeil ( Deceive the Eye ) The texture. Texture map

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

Texture and other Mappings

CS179: GPU Programming

Motivation Hardware Overview Programming model. GPU computing. Part 1: General introduction. Ch. Hoelbling. Wuppertal University

Lecture 4 of 41. Lab 1a: OpenGL Basics

Lectures OpenGL Introduction

Texture Mapping 1/34

MULTI-PASS VS SINGLE-PASS CUBEMAP

Methodology for Lecture

New Concepts. Loading geometry from file Camera animation Advanced lighting and materials Texture mapping Display lists

Department of Computer Sciences Graphics Spring 2013 (Lecture 19) Bump Maps

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Overview. Goals. MipMapping. P5 MipMap Texturing. What are MipMaps. MipMapping in OpenGL. Generating MipMaps Filtering.

Texturing. Slides done by Tomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

OpenGL refresher. Advanced Computer Graphics 2012

OpenGL. Toolkits.

Lecture 5. Scan Conversion Textures hw2

Computer Graphics Texture Mapping

CS GPU and GPGPU Programming Lecture 12: GPU Texturing 1. Markus Hadwiger, KAUST

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2014

INF3320 Computer Graphics and Discrete Geometry

11494 Interactive and GPU Computing Lab. 6-06/05/2015. Textures

Texturing Theory. Overview. All it takes is for the rendered image to look right. -Jim Blinn 11/10/2018

Magnification and Minification

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Textures and normals in ray tracing

Computer Graphics Programming

CS GPU and GPGPU Programming Lecture 16+17: GPU Texturing 1+2. Markus Hadwiger, KAUST

Precept 2 Aleksey Boyko February 18, 2011

Introduction to OpenGL. Prof. Dr.-Ing. Lars Linsen

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Shading. Flat shading Gouraud shading Phong shading

To Do. Review of Last Demo. Methodology for Lecture. Geometry Basic Setup. Outline. Foundations of Computer Graphics (Fall 2012)

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Graphics Pipeline & APIs

Mipmaps. Lecture 23 Subsection Fri, Oct 30, Hampden-Sydney College. Mipmaps. Robb T. Koether. Discrete Sampling.

Computer Graphics. Lecture 8 Antialiasing, Texture Mapping

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Transcription:

Lecture 07: Buffers and Textures CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA October 26, 2010

OpenGL Pipeline Today s Focus Pixel Buffers: read and write image data to and from OpenGL buffers. Textures: map images to OpenGL polygons/surfaces.

Buffer A block of memory with n m k-bit elements. OpenGL Buffers Front + Back buffer Depth buffer Common Properties Precision: numerical accuracy (determined by number of bits). Bitplane: any of the k n m planes in a buffer. Pixel: all k of the bits at a particular spacial location.

Save and Load Buffers Save buffer: retrieve data from buffer and save as image file. Load buffer: retrieve data from image buffer and load buffer. Must be careful that data is reformatted to be compatible with the frame buffer.

Digital Images External Format Images are arrays of pixels, but can be encoded in a variety of formats: EPS, PNG, JPG, BMP, PPM. Internal Representation In OpenGL, images are usually stored as 2D RGB arrays. 1 GLubyte image [ width ][ height ][3]; 2 unsigned char image [ width ][ height ][3];

Portable Pixel Map PPM Format Simple compression-less image format consisting of a short header and body: 1 P6 2 # S i m p l e PPM 3 512 512 4 255 5 <r><g><b >... Library 1 unsigned char * buffer ; 2 s i z e t width, height ; 3 4 ppm_read (" image. ppm ", & buffer, & width, & height ); 5 ppm_write (" image2. ppm ", buffer, width, height );

Saving Buffer to Image File Steps 1. Select appropriate buffer. 2. Retrieve pixels from GPU to CPU. 3. Write buffer to image file. Code 1 glreadbuffer ( GL_ BACK ); 2 glreadpixels (0, 0, width, height, 3 GL_RGB, GL_ UNSIGNED_ BYTE, buffer ); 4 ppm_write (" image. ppm ", buffer, width, height ); As shown in Example 18.

Loading Buffer from Image File Steps 1. Read image file into buffer. 2. Select appropriate buffer. 3. Position raster and configure alignment. 4. Write pixels from CPU to GPU. Code 1 ppm_read (" image. ppm ", & buffer, & width, & height ); 2 gldrawbuffer ( GL_ BACK ); 3 glrasterpos2i (0, 0); 4 glpixelstorei ( GL_ UNPACK_ ALIGNMENT, 1); 5 glreadpixels ( width, height, GL_RGB, 6 GL_ UNSIGNED_ BYTE, buffer ); As shown in Example 20.

OpenGL Pixel Pipeline 1. Unpacking: converts pixels from CPU buffer to internal OpenGL format. 2. Mapping: pixel values mapped using user-defined lookup tables. 3. Testing: check if pixel should be written, and how. 4. Buffer: store pixels in graphics buffer. 5. Packing: convert data from internal OpenGL format to application data format.

Textures Motivation Modeling all details of a surface would require far too much computation and complexity. Method Map a pattern to a OpenGL polygon or surface. Textures are patterns. Patterns are just digital images. Pin texture to polygon or surface.

Texture Mapping Properties Texture is indexed with UV/ST coordinates: (0, 0) (1, 1). Texture usually represents color data, but could be used for other things. A single element is called a texel. Mapping Each vertex gets a set of a texture coordinates, which are used to pin the image onto each polygon.

Texture Mapping Techniques Figure: Spherical Figure: Projections Figure: UV Unwraping Figure: Cylindrical

Basic Texture Mapping in OpenGL Setup 1. Load Image: read texture image from file. 2. Texture Handle: get unique id for texture using glgentextures. 3. Bind Texture: tell state machine to use particular texture using glbindtexture. 4. Set Texture Parameters: use gltexenvf and gltexparameteri to configure texture settings. 5. Copy Image to Texture: use glteximage2d. Usage 1. Enable and Bind Texture: use glenable(gl TEXTURE 2D). 2. Map Texture Coordinates: use gltexcoord2f(s, t).

Texture Setup Example 1 GLuint TextureId ; 2 3 v o i d 4 register_texture ( GLuint *tid, GLubyte *buffer, s i z e t width, s i z e t height ) 5 { 6 glgentextures (1, tid ); 7 glbindtexture ( GL_TEXTURE_2D, *tid ); 8 glpixelstorei ( GL_UNPACK_ALIGNMENT, 1); 9 gltexparameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 10 gltexparameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 11 gltexparameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 12 gltexparameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 13 gltexenvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 14 glteximage2d ( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, 15 GL_RGB, GL_UNSIGNED_BYTE, buffer ); 16 } 17 18 i n t 19 main ( i n t argc, char *argv []) 20 { 21 unsigned char * buffer ; 22 s i z e t width, height ; 23 24 ppm_read (" texture.ppm ", &buffer, &width, & height ); 25 register_texture (& TextureId, buffer, width, height ); 26 }

Texture Usage Example 1 v o i d 2 display () 3 { 4 double width = ( GLdouble ) ImageWidth /( GLdouble ) ImageHeight ; 5 double height = 1.0; 6 7 glclear ( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); 8 9 glmatrixmode ( GL_MODELVIEW ); 10 glloadidentity (); 11 glulookat (EyeX, EyeY, EyeZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 12 13 glenable ( GL_TEXTURE_2D ); 14 glbindtexture ( GL_TEXTURE_2D, ImageTextureId ); 15 16 glcolor3f (1.0, 1.0, 1.0); 17 glbegin ( GL_QUADS ); { 18 gltexcoord2f (0.0, 0.0); 19 glvertex3f (- width, -height, 0.0); 20 21 gltexcoord2f (1.0, 0.0); 22 glvertex3f ( width, -height, 0.0); 23 24 gltexcoord2f (1.0, 1.0); 25 glvertex3f ( width, height, 0.0); 26 27 gltexcoord2f (0.0, 1.0); 28 glvertex3f (- width, height, 0.0); 29 } glend (); 30 } As shown in Example 21.

Texture Parameters TEXTURE ENV MODE GL MODULATE: texture colors object colors. GL REPLACE: disable lighting and just use texture colors. GL DECAL: when there s alpha, draw texture with α and let object s colors bleed through. TEXTURE MIN MAG FILTER GL NEAREST: simplest nearest neighbor replacement. GL LINEAR: linear interpolation for smoother values. TEXTURE WRAP S T GL REPEAT: repeat pattern. GL CLAMP: use edge values.

Texture Magnification/Minification Filtering Magnification: texel is larger than 1 pixel. Minification: texel is smaller than 1 pixel.

Texture Mipmapping Mipmapping Create copies of the texture at smaller resolutions and then index into those when the depth at the pixel is far away to avoid antialiasing.

Texture Wrapping What happens if we map texture coordinates > (1, 1)? Figure: Repeat Figure: Clamp

Bump Mapping Distorts the normal vectors during shading process to make the surface appear to have small variations in shape. Figure: Smooth Sphere Figure: Bump Map Figure: Orange