Programming Textures Lecture 15 Fri, Sep 28, 2007.

Slides:



Advertisements
Similar presentations
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
Advertisements

1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
OpenGL Texture Mapping
Texture Mapping OpenGl and Implementation Details CS
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Computer Graphics Texture Mapping Eriq Muhammad Adams
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
2002 by Jim X. Chen: 1 Texture Lab At each rendered pixel, selected texels are used either to substitute for or to scale.
Lecture 8: Texture Mapping 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping. Introduction What is Texture Mapping? Types of Texture Mapping –1D, 2D and 3D SDL and OpenGL.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
An Interactive Introduction to OpenGL Programming Ed Angel
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
Lecture 27: Texture Mapping Li Zhang Spring 2008
And Some Extra Information From
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
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.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
TEXTURE CSE 410. Add Texture to Polygon glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,texid); // here texid corresponds a bitmap image. glNormal3f(1.0,0.0,0.0);
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Textures – Basic Principles Lecture 29 Fri, Nov 14, 2003.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Madhulika (18010), Assistant Professor, LPU.
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
texturing a parametric surface
Advanced Graphics Algorithms Ying Zhu Georgia State University
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
Introduction to Texture Mapping
Lecture 21: Texture mapping Li Zhang Spring 2010
Mipmaps Lecture 16 Mon, Oct 1, 2007.
3D Game Programming Texture Mapping
Textures Lecture 11 Wed, Oct 5, 2005.
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Mipmaps Lecture 13 Wed, Oct 12, 2005.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

Programming Textures Lecture 15 Fri, Sep 28, 2007

Creating Texture Objects To create a texture object internally, Create a 3-dimensional array of unsigned bytes (chars) First dimension = row number Second dimension = column number Third dimension = RGB level Assign to each byte a value from 0 to 255.

Creating Texture Objects GLubyte image[64][64][3]; void makeImage() { // Make black and white checkerboard for (int i = 0; i < 64; i++) for (int j = 0; j < 64; j++) if ((i & 0x8) == (j & 0x8)) image[i][j][0] = 0; image[i][j][1] = 0; image[i][j][2] = 0; } : return;

Creating Texture Objects The function glPixelStore*() tells how texels are stored. 1 = on byte boundaries. 2 = on word boundaries. 4 = on long-word boundaries. We will use glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

Creating Texture Objects We need to create a texture object. A texture object has an internal structure determined by OpenGL. OpenGL will give us a reference number to the object which we will use to access it. Declare an array of unsigned integers to hold the reference numbers. unsigned int texName[number];

Creating Texture Objects The function call glGenTextures(number, texName); will return the specified number of integers to represent texture objects. These integers are stored in the array texName.

Creating Texture Objects The function call glBindTexture(GL_TEXTURE_2D, texName[i]); is used to Initialize a texture object. Make a specified texture object the active texture. The first time texName[i] is used, the object is initialized and made active. In all subsequent uses, texName[i] becomes the active texture.

Creating Texture Objects The function glTexImage2D() defines the image of the current texture object. glTexImage2D(GL_TEXTURE_2D, level, internal format, width, height, border, image format, image type, ptr to image); level is used if we are supplying multiple levels of detail, 0 otherwise. internal format is usually GL_RGB or GL_RGBA.

Creating Texture Objects width and height must be powers of two. border is 0 if there is no border, 1 otherwise. image format is the format of the data in the external image array, usually GL_RGB or GL_RGBA. image type is the data type of each value in the image array, usually unsigned byte. ptr to image is a pointer to the image array.

Creating Texture Objects A typical function call is glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

Texture Coordinates Each texture has its own coordinate system. s is the horizontal axis; t is the vertical axis. The texture coordinates are always 0  s  1, 0  t  1. 1 t s 1

Mapping Textures To apply a texture to a polygon, we must map a pair of texture coordinates (s, t) to each vertex (x, y, z) of the polygon. glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-4.0, -3.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(4.0, -3.0, 0.0); : glEnd();

Applying Textures We have several choices concerning how the texture is applied to the polygon Replace, blend, decal, or modulate. Repeat or clamp. Use nearest texel or interpolate texels. The most common combination of choices is replace, repeat, and interpolate.

Applying Textures We use the function glTexEnv*() to specify whether to replace, blend, decal, or modulate the face color with the texture color. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); Other choices for the third parameter are GL_BLEND, GL_DECAL, and GL_MODULATE.

Applying Textures The function glTexParameter*() is used to make the other choices. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); We can also use GL_TEXTURE_WRAP_T for the t direction. GL_CLAMP to clamp s or t to [0, 1].

Applying Textures glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); We can also use GL_TEXTURE_MIN_FILTER for minification. GL_LINEAR for interpolation.

Applying Textures Finally, textures must be enabled. glEnable(GL_TEXTURE_2D); Textures can also be disabled. glDisable(GL_TEXTURE_2D);

Example void init() { makeImage(); // Create texture object glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(3, texName); glBindTexture(GL_TEXTURE_2D, texName[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); // Set mode of texture application glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_2D); : }

Brick Wall Texture Example Read Run

Bitmaps A bitmap file (.bmp) is a file that contains the color of each pixel of a rectangular region. A bitmap file also contains some header information. See http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Format of a Bitmap File A bitmap file has the following format. Bitmap file header 2 chars – ‘B’, ‘M’ for “bitmap” int – Total file size of file, in bytes short int – 0 int – offset to pixel data, in bytes Bitmap info header int – size of header, in bytes int – width of image, in pixels

Format of a Bitmap File int – height of image, in pixels short int – number of planes (1) short int – bits per pixel 1 = 2 colors (color table) 4 = 16 colors (color table) 8 = 256 colors (color table) 24 = millions of colors (RGB triples) int – compression (0 = no compression) int – image size in bytes int – pixels per meter horizontally (0)

Format of a Bitmap File The pixel data int – pixels per meter vertically (0) int – number of colors used in color table, or 0 int – number of important colors (0 = all) The pixel data A linear array of RGB triples, padded so that the number of bytes in each row is a multiple of 4.

Reading Bitmaps We will use a function readBitmap(filename); that will read the information from the bitmap file and store the relevant information in a Bitmap object. The Bitmap class assumes that the bitmap file uses 24-bit color. It will not handle other formats.

Reading Bitmaps The Bitmap class has the following public member functions. readBitmap(filename) – read the bitmap info from the specified file. imageWidth() – the width of the image, in pixels. imageHeight() – the height of the image, in pixels. imageData() – a pointer to an array of RGB values.

Bitmap Texture Read Run