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

Similar documents
The Graphics Pipeline

CS 432 Interactive Computer Graphics

The Graphics Pipeline

Magnification and Minification

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

The Projection Matrix

The Mesh Class. Lecture 23. Robb T. Koether. Hampden-Sydney College. Wed, Oct 18, 2017

Discussion 3. PPM loading Texture rendering in OpenGL

The Critical-Path Algorithm

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

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

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

The Projection Matrix

Ambient and Diffuse Light

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

Computergraphics Exercise 15/ Shading & Texturing

The Traveling Salesman Problem Brute Force Method

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

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

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

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

Lighting and Texturing

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

GLSL Overview: Creating a Program

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

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

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

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

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

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

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Minimal Spanning Trees

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Overview. By end of the week:

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

CT5510: Computer Graphics. Texture Mapping

Recursive Linked Lists

ก ก ก.

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Texture Mapping 1/34

Scheduling and Digraphs

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

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

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

LR Parsing - Conflicts

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE

CPSC 436D Video Game Programming

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Rotations and Translations

The Class Construct Part 1

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Texture Mapping 1/34

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

Nondeterministic Programming in C++

Lecture 31 Sections 9.1, 9.2, 9.3. Mon, Nov 23, 2009

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Lecture 9(B): GPUs & GPGPU

Scope and Parameter Passing

CS179: GPU Programming

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

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Methodology for Lecture

Implementing Linked Lists

Stacks and their Applications

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

The Decreasing-Time Algorithm

The Pairwise-Comparison Method

Tutorial 3: Texture Mapping

Introduction to Computer Graphics with WebGL

Geometry Shaders. And how to use them

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

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

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

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

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

MySQL Creating a Database Lecture 3

The Plurality-with-Elimination Method

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

Street-Routing Problems

2D graphics with WebGL

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

Density Curves Sections

Sampling Distribution Examples Sections 15.4, 15.5

Solving Recursive Sequences by Iteration

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Dynamic Allocation of Memory

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

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

XQuery FLOWR Expressions Lecture 35

Binary Tree Applications

Transcription:

Applying Textures Lecture 27 Robb T. Koether Hampden-Sydney College Fri, Nov 3, 2017 Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 1 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 2 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 3 / 24

Applying Textures To apply a texture that was internally generated (e.g., the checkerboard), we must do the following Create a texture name The name is an unsigned integer. Generate a texture - OpenGL will assign a value to the name. Bind the texture Create the (empty) texture object. Copy the texels to the texture object. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 4 / 24

Applying Textures To apply a texture that was internally generated (e.g., the checkerboard), we must do the following Create a texture name The name is an unsigned integer. Generate a texture - OpenGL will assign a value to the name. Bind the texture Create the (empty) texture object. Copy the texels to the texture object. This is the same pattern that we used for vertex buffer objects and vertex array objects. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 4 / 24

Applying Textures Applying Textures GLuint checkerboard; glgentextures(1, &checkerboard); glbindtexture(gl_texture_2d, checkerboard); glteximage2d(gl_texture_2d, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, tex_checkerboard_data); Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 5 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 6 / 24

Photographs as Textures The file vdds.cpp contains functions that greatly simplify converting photographs to textures. The functions vglloadimage() and vglloadtexture() do all the work for us. vglloadtexture() creates internally an vglimagedata object. After it has copied the texture to the shaders, it deletes the vglimage Data object. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 7 / 24

The vglimagedata Object The vglimagedata Object struct vglimagedata { GLenum target; // E.g., GL_TEXTURE_2D GLenum internalformat // E.g., GL_RGB GLenum format // E.g., GL_RGB GLenum type; // E.g., GL_RGB GLsizei miplevels; // Number of mipmap levels GLsizei slices; // For arrays GLsizeiptr slicestride; // Distance between slices GLsizeiptr totaldatasize; // Total number of bytes vglimagemipdata mip[]; // Mipmap data }; Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 8 / 24

The vglloadimage() Function The vglloadimage() Function void vglloadimage(const char* filename, vglimagedata* image); The vglloadimage() function reads the image data from the specified file and stores it in a vglimagedata object. The file type must be.dds (DirectDraw Surface), a Microsoft creation. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 9 / 24

The vglloadimage() Function The vglloadimage() Function void vglloadimage(const char* filename, vglimagedata* image); The vglloadimage() function reads the image data from the specified file and stores it in a vglimagedata object. The file type must be.dds (DirectDraw Surface), a Microsoft creation. We do not need to call this function directly, because it is called by the next function... Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 9 / 24

The vglloadtexture() Function The vglloadtexture() Function void vglloadtexture(const char* filename, GLuint texture, vglimagedata* image); The vglloadtexture() function Creates a vglimagedata object. Reads the image into it. Generates and binds the texture object. Copies the data from the vglimagedata object to the texture object. Destroys the vglimagedata object. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 10 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 11 / 24

The Application Program The Application Program enum {vposition = 0,..., vtexture = 3}; enum {GrassTex, RoadTex,..., NumTextures}; GLuint Texture[NumTextures]; glgentextures(numtextures, Texture); We follow the same pattern used for VBOs and VAOs. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 12 / 24

The Application Program The Application Program vglloadtexture("pathname/grass.dds", Texture[GrassTex], &image); vglloadtexture("pathname/road.dds", Texture[RoadTex], &image);. We follow the same pattern used for VBOs and VAOs. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 13 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 14 / 24

The Vertex Array Object The Vertex Array Object struct VertexDataTex3D { vec3 pos; vec3 norm; vec2 tex; }; Just as we added the coordinates of the normal vectors for each vertex, we must add the texture coordinates for each vertex. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 15 / 24

The Vertex Array Object The Vertex Array Object glvertexattribpointer(vtexture, 2, GL_FLOAT,...); glenablevertexattribarray(vtexture); Describe the structure of the buffer, including the texture coordinates. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 16 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 17 / 24

The Vertex Shader The Vertex Shader layout (location = 3) in vec2 vtexture; out vec2 tex_coord; tex_coord = vtexture; In the vertex shader, we need only the texture coordinates for the vertex. They should be included in the vertex buffer along with the position and normal vectors. These coordinates will be passed to the fragment shader, where they will be interpolated across the primitive. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 18 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 19 / 24

The Fragment Shader The Fragment Shader uniform sampler2d tex; in vec2 tex_coord; // From the vertex shader A sampler2d object is the uniform variable that holds the texture object. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 20 / 24

The texture() Function The texture() Function vec4 texel = texture(tex, tex_coord); The texture() function uses the texture coordinates to return a vec4 object (RGBA) from the array of texels. This value is used in place of the color (ambient and diffuse) or is blended with the color. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 21 / 24

The Fragment Shader The Fragment Shader uniform bool use_tex; We could add a uniform bool, which can be set independently for each object, that is true if textures are to be applied and false otherwise. If use_tex is true, then texel is used. If use_tex is false, then the material colors are used. Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 22 / 24

Outline 1 Applying Textures 2 Photographs as Textures 3 The Application Program 4 The Vertex Array Object 5 The Vertex Shader 6 The Fragment Shader 7 Assignment Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 23 / 24

Homework Homework Read pages 259-263: Texture Mapping & Basic Texture Types Read pages 270-277: Texture Formats Robb T. Koether (Hampden-Sydney College) Applying Textures Fri, Nov 3, 2017 24 / 24