UniS CS293 Graphics with Java and OpenGL Textures.

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

Virtual Realism TEXTURE MAPPING. The Quest for Visual Realism.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Texture and Colour in Virtual Worlds Programming for 3D Applications.
Texture Visual detail without geometry. Texture Mapping desire for heightened realism.
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
OpenGL Texture Mapping
Graphics Systems I-Chen Lin’s CG slides, Doug James’s CG slides Angel, Interactive Computer Graphics, Chap 1 Introduction to Graphics Pipeline.
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Guilford County Sci Vis V204.01
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Computer Graphics Inf4/MSc Computer Graphics Lecture 9 Antialiasing, Texture Mapping.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
UniS CS297 Graphics with Java and OpenGL Introduction.
Computer Graphics Texture Mapping Eriq Muhammad Adams
Computer Graphics Texture Mapping
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Lecture 8: Texture Mapping 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
CS 376 Introduction to Computer Graphics 04 / 11 / 2007 Instructor: Michael Eckmann.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
UniS CS293 Graphics with Java and OpenGL Introduction.
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
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
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. [
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.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
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.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
CHAPTER 8 Color and Texture Mapping © 2008 Cengage Learning EMEA.
More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
UniS CS297 Graphics with Java and OpenGL Blending.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
1 Perception and VR MONT 104S, Fall 2008 Lecture 20 Computer Graphics and VR.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Textures – Basic Principles Lecture 29 Fri, Nov 14, 2003.
Module 05 –Bump mapping Module 05 – Bump mapping Module 05 Advanced mapping techniques: Bump mapping.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Discrete Techniques.
OpenGL Texture Mapping
OpenGL Texture Mapping
Chapters VIII Image Texturing
Introduction to Texture Mapping
3D Game Programming Texture Mapping
OpenGL Texture Mapping
CS297 Graphics with Java and OpenGL
OpenGL Texture Mapping
Advanced Computer Graphics: Texture
OpenGL Texture Mapping
Presentation transcript:

UniS CS293 Graphics with Java and OpenGL Textures

UniS 2 Material from the Redbook is extensively used throughout these slides. Code has been translated from C++ to JOGL based on examples from the book

UniS 3 Overview Understand what texture mapping can add to your scene Specify a texture image Control how a texture image is filtered as it's applied to a fragment Create and manage texture images in texture objects Supply texture coordinates to indicate how the texture image should be aligned to the objects in your scene Use automatic texture coordinate generation

UniS 4 Texture mapping To draw a large brick wall without texture mapping, each brick must be drawn as a separate polygon. Without texturing, a large flat wall might need thousands of individual bricks Texture mapping allows you to glue an image of a brick wall (obtained, perhaps, by scanning in a photograph of a real wall) to a polygon draw the wall as a single polygon. Texture mapping ensures that all the right things happen as the polygon is transformed and rendered. E.g. when viewed in perspective, the bricks appear smaller as the wall gets farther from the viewpoint. Textures can also be used in flight simulation textures to create the illusion of natural.

UniS 5 Texture mapping Textures can be mapped to surfaces made of a set of polygons or to curved surfaces, and you can repeat a texture in one or both directions to cover the surface. A texture can be one-dimensional. You can automatically map a texture onto an object in such a way that the texture indicates contours or other properties of the item being viewed. Shiny objects can be textured so that they appear to be in the centre of a room or other environment, reflecting the surroundings off their surfaces. A texture can be applied to a surface in different ways. It can be painted on directly, used to modulate the colour the surface would have been painted otherwise, or used to blend a texture colour with the surface colour.

UniS 6 Texture mapping Textures are simply rectangular arrays of data - for example, colour data, luminance data, or colour and alpha data. The individual values in a texture array are often called texels. What makes texture mapping tricky is that a rectangular texture can be mapped to nonrectangular regions, and this must be done in a reasonable way.

UniS 7 Texture mapping A quadrilateral displayed on the screen might be distorted by applying various transformations - rotations, translations, scaling, and projections. The figure shows how the texture- mapped quadrilateral might appear on your screen after these transformations. The quadrilaterals are only distorted by perpesctive transformations and rotations in 3D. Three of the quads are squares the front one is arbitrary. Note how the texture image of rectangular text is distorted to fit into a non-rectangular region. Note we have also used blending to show all the quads at the same time.

UniS 8 Steps in Texture Mapping To use texture mapping, you perform these steps. 1.Create a texture object and specify a texture for that object. 2.Indicate how the texture is to be applied to each pixel. 3.Enable texture mapping. 4.Draw the scene, supplying both texture and geometric coordinates.

UniS 9 Create a Texture Object and Specify a Texture for That Object A texture is usually thought of as being two- dimensional, like most images, but it can also be one-dimensional. The data describing a texture may consist of one, two, three, or four elements per texel, representing anything from a modulation constant to an (R, G, B, A) quadruple.

UniS 10 Indicate How the Texture Is to Be Applied to Each Pixel Four possible functions for computing the final RGBA value from the fragment color and the texture-image data. 1.Use the texture color as the final color; the decal mode, the texture is painted on top of the fragment 2.The replace mode, a variant of the decal mode. 3.Use the texture to modulate, or scale, the fragment's color; this technique is useful for combining the effects of lighting with texturing. 4.Finally, a constant color can be blended with that of the fragment, based on the texture value.

UniS 11 Enable Texture Mapping gl.glEnable(GL.GL_TEXTURE_2D); gl.glDisable(GL.GL_TEXTURE_2D);

UniS 12 Texture and Geometric Coordinates Define how the texture is aligned relative to the fragments its applied to before it's "glued on.“ For a two-dimensional texture map the texture coordinates range from 0.0 to 1.0 in both directions, but the coordinates of the items being textured can be anything. Define how texture coordinates outside the range [0.0,1.0] should be treated. Do textures repeat, or are they clamped to a boundary value?

UniS 13 Jpeg images for textures It is not part of this course to cover the conversion of Jpg, or other image format, into texture maps. In order to have interesting examples we use the library NeHe Java ports from: The NeHe tutorials are written for OpenGL, not JOGL. The web site is Lab material contains details of how to use these ports for coding purposes.

UniS 14 Coding conventions String[ ] textureNames = new String[ ] { "demos/data/images/mona-lisa.png", "demos/data/images/monkey.jpg", "demos/data/images/newton2.jpg", "demos/data/images/marilyn.jpg", "demos/data/images/SEPS_Computing.png" }; The coding convention for all the lab material is to store image names in the textureNames array, and manipulate this field directly to generate texture maps.

UniS 15 Coding conventions Textures in JOGL are given identifiers that are integer values. Thus our list of images is converted into textures who’s identifiers can be stored in an integer array. Our convention is to define this as a field: private int textures[] = new int[textureNames.length];

UniS 16 NeHe library methods TextureReader This is a NeHe class that permits us to load a Jpg image directly into a Texture object. Texture is and internal class to TextureReader that is used as a temporary place holder for textures. Following code shows how these classes are used in a NeHe routine to attach textures to an integer array of texture identifiers.

UniS 17 loadGLTextures method, version 1 public void loadGLTextures(GL gl) throws IOException { gl.glGenTextures(textureNames.length, textures, 0); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL); for (int textureIndex = 0; textureIndex < textureNames.length; textureIndex++) { String textureName = textureNames[textureIndex]; TextureReader.Texture texture = TextureReader.readTexture(textureName); imageW[textureIndex] = texture.getWidth(); imageH[textureIndex] = texture.getHeight(); gl.glBindTexture(GL.GL_TEXTURE_2D, textures[textureIndex]); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8, texture.getWidth(), texture.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, texture.getPixels()); }

UniS 18 glTexEnvf gl.glTexEnvf( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL); Defines the mode for combining texture map with geometric model In this case GL_DECAL specifies that the texture will be attached to the surface of the polygon and replace the material characteristics of the polygon.

UniS 19 Loading Texture String textureName = textureNames[textureIndex]; TextureReader.Texture texture = TextureReader.readTexture( textureName); imageW[textureIndex]=texture.getWidth(); imageH[textureIndex]=texture.getHeight(); These lines of code use the TextureReader.readTexture method to load in a particular Jpeg and convert it to a texture. This is stored in the internal variable texture.

UniS 20 Binding the texture gl.glBindTexture(GL.GL_TEXTURE_2D, textures[textureIndex]); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, GL.GL_RGB8, texture.getWidth(), texture.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, texture.getPixels());

UniS 21 Binding the texture glGenTextures() and glBindTexture() name and create a texture object for a texture image. The single, full-resolution texture map is specified by glTexImage2D(), whose parameters indicate –size of the image, –type of the image, –location of the image, –and other properties of it.

UniS 22 Filtering Texture maps are square or rectangular After being mapped to a polygon or surface and transformed into screen coordinates, the individual texels rarely correspond to individual pixels. Depending on the transformations used and the texture mapping applied, a single pixel on the screen can correspond to anything from a tiny portion of a texel (magnification) to a large collection of texels (minification) Texture Polygon Texture Polygon texel portion texel group pixel Magnification Minification

UniS 23 Filtering gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); These lines define how to compute texel magnification and minification.

UniS 24 Texture coordinates (in display method) gl.glPushMatrix(); gl.glBindTexture(GL.GL_TEXTURE_2D, textures[filter1]); float text_crd = 8f; gl.glTranslatef(0.0f, 0.0f, -2.0f * square_x); gl.glScalef(((float)imageW[filter1])/((float)imageH[filter1]), 1.0f, 1.0f); gl.glBegin(GL.GL_QUADS); gl.glNormal3f(0.0f, 0.0f, 1.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-15.0f, -15.0f, 15.0f); gl.glTexCoord2f(text_crd, 0.0f); gl.glVertex3f(15.0f, -15.0f, 15.0f); gl.glTexCoord2f(text_crd,text_crd); gl.glVertex3f(15.0f, 15.0f, 15.0f); gl.glTexCoord2f(0.0f, text_crd); gl.glVertex3f(-15.0f, 15.0f, 15.0f); gl.glEnd(); gl.glPopMatrix(); Define a mapping that describes how the texture is pasted on top of any polygon

UniS 25 Repeating textures gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-15.0f, -15.0f, 15.0f); gl.glTexCoord2f(text_crd, 0.0f); gl.glVertex3f(15.0f, -15.0f, 15.0f); gl.glTexCoord2f(text_crd,text_crd); gl.glVertex3f(15.0f, 15.0f, 15.0f); gl.glTexCoord2f(0.0f, text_crd); gl.glVertex3f(-15.0f, 15.0f, 15.0f); When texture coordinates are larger than 1.0f, then the texture can either be cropped, or repeated.

UniS 26 Repeating textures If we use the following lines within the loadGLTextures method, then the texture will be repeated when its texture coordinates exceed 1.0f gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);

UniS 27 Repeating textures In this case taking text_crd = 8.0f results in the polygon containing an 8x8 grid of the texture.

UniS 28 Modulating textures Use the command gl.glTexEnvf( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); Instead of gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL); Then the colour properties of the material we are texture mapping will modulate how the final image appear.

UniS 29 Modulating textures Here the material has pure red diffuse material set. Note since we have blending enabled we also have transparency