ก ก ก.

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

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

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

CS212. OpenGL Texture Mapping and Related

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

CT5510: Computer Graphics. Texture Mapping

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Texture Mapping. Mike Bailey.

Grafica Computazionale

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

CS 432 Interactive Computer Graphics

Discussion 3. PPM loading Texture rendering in OpenGL

Lecture 07: Buffers and Textures

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

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

Steiner- Wallner- Podaras

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

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

Lighting and Texturing

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

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

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

Texture Mapping and Sampling

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

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

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

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

9.Texture Mapping. Chapter 9. Chapter Objectives

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

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

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

Lecture 5. Scan Conversion Textures hw2

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

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

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

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

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

Imaging and Raster Primitives

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Computergraphics Exercise 15/ Shading & Texturing

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

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

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

Methodology for Lecture

Computational Strategies

Chapter 6 Texture Mapping

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

Computer Graphics Texture Mapping

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

Shading/Texturing. Dr. Scott Schaefer

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

INF3320 Computer Graphics and Discrete Geometry

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

Texture and other Mappings

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

CS179: GPU Programming

Image I/O and OpenGL Textures

Textures. Datorgrafik 2006

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

Magnification and Minification

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

Introduction to OpenGL

IntMu.Lab5. Download all the files available from

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

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

OpenCL / OpenGL Texture Interoperability: An Image Blurring Case Study

Texture Mapping 1/34

Lecture 5 3D graphics part 3

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

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access

Computer Graphics Texture Mapping

Stored Texture Shaders

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

CSE 167: Lecture #17: Volume Rendering. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

INF3320 Computer Graphics and Discrete Geometry

GLSL Overview: Creating a Program

Texture mapping. Computer Graphics CSE 167 Lecture 9

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Texture Mapping and Special Effects

Computer Graphics

Texture. No Textures

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

Texture Mapping 1/34

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

Overview. By end of the week:

OpenGL Über Buffers Extension

Shading System Immediate-Mode API v2.2

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

Page 6 PROCESSOR PROCESSOR FRAGMENT FRAGMENT. texy[1] texx. texy[1] texx. texy[0] texy[0]

Chapter 3. Texture mapping. Learning Goals: Assignment Lab 3: Implement a single program, which fulfills the requirements:

1)Write a shader program that renders a regular pentagon with textured image like the one shown below.

MULTI-PASS VS SINGLE-PASS CUBEMAP

Shading. Flat shading Gouraud shading Phong shading

LSU EE Homework 3 Solution Due: 12 October 2015

Transcription:

418382 ก ก ก ก 5 pramook@gmail.com

TEXTURE MAPPING

Textures Texture Object An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them Provides efficiency gains over having to repeatedly load and reload a texture You can prioritize textures to keep in memory OpenGL uses least recently used (LRU) if no priority is assigned

Step 1 create Texture Objects glgentextures(1, &texture[texture_num texture_num]); First argument tells GL how many Texture Objects to create Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it creates texture[ ] is of type GLuint

Step 2 Specify which texture object is about to be defined Tell OpenGL that you are going to define the specifics of the Texture Object it created glbindtexture(gl_texture_2d, texture[texture_num]); Textures can be 1D and 3D as well

Step 3 Begin defining texture gltexparameter() Sets various parameters that control how a texture is treated as it s applied to a fragment or stored in a texture object // scale linearly when image bigger than texture gltexparameteri(gl_texture_2d,gl_texture_mag_ FILTER,GL_LINEAR); // scale linearly when image smaller than texture gltexparameteri(gl_texture_2d,gl_texture_min_ FILTER,GL_LINEAR);

Step 4 Assign image data glteximage2d(); GL_TEXTURE_2D (2D Texture) 0 (level of detail 0) 3 (3 components, RGB) image1->sizex image1->sizey (size) (size) 0 (no border pixel) GL_RGB GL_UNSIGNED_BYTE image1->data (RGB color order) (unsigned byte data) (pointer to the data))

glteximage2d Arg 1 GLenum target GL_TEXTURE_{1 2 3}D GL_PROXY_TEXTURE_2D Provides queries for texture resources Proceed with hypothetical texture use (GL won t apply the texture) After query, call GLGetTexLevelParamter to verify presence of required system components Doesn t check possibility of multiple texture interference

glteximage2d Arg 2 GLint level Used for Level of Detail (LOD) LOD stores multiple versions of texture that can be used at runtime (set of sizes) Runtime algorithms select appropriate version of texture Pixel size of polygon used to select best texture Eliminates need for error-prone filtering algorithms

glteximage2d Arg 3 GLint internalformat GL defines 38 symbolic constants that describe which of R, G, B, and A are used in internal representation of texels Provides control over things texture can do High bit depth alpha blending High bit depth intensity mapping General purpose RGB GL doesn t guarantee all options are available on given hardware

glteximage2d Args 4-6 GLsizei width GLsizei height Dimensions of texture image Must be 2 m + 2b (b=0 or 1 depending on border) min, 64 x 64 GLint border Width of border (1 or 0) Border allows linear blending between overlapping textures Useful when manually tiling textures

glteximage2d Args 7 & 8 GLenum format Describe how texture data is stored in input array GL_RGB, GL_RGBA, GL_BLUE GLenum type Data size of array components GL_SHORT, GL_BYTE, GL_INT

glteximage2d Arg 9 Const GLvoid *texels Pointer to data describing texture map

Step 5 Apply texture Before defining geometry glenable(gl_texture_2d); glbindtexture(gl_texture_2d, texture[0]); gltexenvf(gl_texture_env, GL_TEXTURE_ENV_MODE, GL_REPLACE);

gltexenv() First argument to function is always GL_TEXTURE_ENV GL_TEXTURE_ENV_MODE If GL_BLEND selected, second call to gltexenv() must specify GL_TEXTURE_ENV_COLOR GL_DECAL (alpha blends texture with poly color) GL_REPLACE (straight up replacement) GL_MODULATE (texture application is a function of poly lighting) GL_BLEND (texture controls blending with another color) 4-float array for R,G,B,A blend

MIPMAPPING

MIPMAPS With versus without MIPMAP

Filtering OpenGL tries to pick best mipmap level Question: Which texel corresponds to a particular pixel? GL_NEAREST (Point Sampling) Pick the texel with center nearest pixel GL_LINEAR (Bilinear Sampling) Weighted average of 2x2 closest texels GL_NEAREST_MIPMAP_LINEAR Average nearest texels from two mipmap levels GL_LINEAR_MIPMAP_LINEAR (Trilinear Trilinear) Average two averaged texels from two mipmaps

DEVIL

DevIL ก.jpg,.png,.tiff, ก OpenGL http://openil.sourceforge.net DevIL1.7.8 SDK for 32-bit Windows Unzip.dll bin CMake.lib lib CMake.h include/il CMake

include #include <IL/il.h> #include <IL/ilu.h> #include <IL/ilut.h> #include <IL/ilut.h> ก

ก init DevIL ก main ilinit(); iluinit(); ก ก ก ก ilutinit(); ก glutinit( );

Image Object DevIL ก texture OpenGL ilgenimages ก ilbindimage ก illoadimage ildeleteimages

ilgenimages ILvoid ilgenimages( ILsizei Num, ILuint*ids); image object argument ก image object ก argument image object ก image object ILuintid; ilgenimages(1, &id); ก image object ILuintid[3]; ilgenimages(3, id);

ilbindimage ILvoid ilbindimage(iluint id) image object image object ก ILuintid; ilgenimages(1, &id); ilbindimage(id);

illoadimage ILboolean illoadimage(const char *FileName) ก ก image object bind argument ก DevIL ILuintid; ilgenimages(1, &id); ilbindimage(id); illoadimage( test.jpg );

ildeleteimages ILvoid ildeleteimages( ILsizei Num, ILuint*ids); image object argument ก image object ก argument image object ก image object ILuintid; ildeleteimages(1, &id); ก image object ILuintid[3]; ilgenimages(3, id); ildeleteimages(3, id);

ilconvertimage ILbooleanilConvertImage( ILenum DestFormat, ILenum DestType) bind DestFormat pixel IL_RGB, IL_RGBA, IL_BGR, IL_BGRA, IL_LUMINANCE, IL_COLOUR_INDEX DestType ก IL_BYTE, IL_UNSIGNED_BYTE, IL_SHORT, IL_UNSIGNED_SHORT, IL_INT, IL_UNSIGNED_INT, IL_FLOAT, IL_DOUBLE

ก OpenGL Texture ก glteximage2d ก Image Object internalformat ilgetinteger(il_image_bpp) width ilgetinteger(il_image_width) height ilgetinteger(il_image_height) format ilgetinteger(il_image_format) type ilgetinteger(il_image_type) data ilgetdata()

ilgetdata ILubyte* ilgetdata(ilvoid) image object bind unsigned byte

ก glgentextures(1, &tex0); glbindtexture(gl_texture_2d, tex0); 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_LINEAR_MIPMAP_LINEAR); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); ILuint image0; ilgenimages(1, &image0); ilbindimage(image0); char imagename[] = "../../data/yellow-flowers.jpg"; illoadimage(imagename); ilconvertimage(il_rgb, IL_UNSIGNED_BYTE); glubuild2dmipmaps(gl_texture_2d, ilgetinteger(il_image_bpp), ilgetinteger(il_image_width), ilgetinteger(il_image_height), ilgetinteger(il_image_format), ilgetinteger(il_image_type), ilgetdata()); ildeleteimages(1, &image0);