CS 480/680 (Fall 2018) Part 2: Texture Loading

Slides:



Advertisements
Similar presentations
1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
Advertisements

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
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
GLSL Applications: 2 of 2 Patrick Cozzi University of Pennsylvania CIS Spring 2011.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
OpenGL. Textures  Bind Textures similar to binding VBO’s  Create a texture for each object  Generate the texture similar how you generate a VBO buffer.
Texturing in OpenGL Lab #7. Creating Textures glEnable ( GL_TEXTURE_2D ); GLuint myTex; glGenTextures ( 1, (GLuint*) &myTex ); glBindTexture ( GL_TEXTURE_2D,
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.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
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 Shading Language (GLSL)
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
OpenGL Shading Language (GLSL)
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
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.
MP3 Frequently Asked Questions (IN OFFICE HOURS).
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
Wilf Comp Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
MP3.. Start at the very beginning. Almost. Either start from nothing yourself, or use the empty template for this MP. Run through the provided files are.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Shaders, part 2 alexandri zavodny.
Real-Time Rendering Buffers in OpenGL 3.3
© University of Wisconsin, CS559 Spring 2004
Tips for Environment Mapping
Real-Time Rendering Geometry and Buffers
Texture Mapping Part II
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
Chapters VIII Image Texturing
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
© University of Wisconsin, CS559 Fall 2004
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
OpenGL Texture Mapping
Programming with OpenGL Part 3: Shaders
Programming with OpenGL Part 5: More GLSL
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
OpenGL Texture Mapping
Programming with OpenGL Part 5: More GLSL
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
Programming Textures Lecture 15 Fri, Sep 28, 2007.
CS 480/680 Part 1: Model Loading.
Textures in WebGL.
Assimp.
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

CS 480/680 (Fall 2018) Part 2: Texture Loading

Today’s Topics What are Textures? Textures and Assimp Image Libraries Textures and OpenGL References Questions

What are Textures? Textures are a method for giving your objects a more sophisticated and realistic color scheme.

Textures and Assimp const aiScene *myScene = importer.ReadFile(yourObjFile, aiProcess_Triangulate); Remember how myScene points to an impressively large data structure? We then used this data structure to obtain the vertex coordinate info to render our models. Now, we’re going to use that data structure to obtain the texture mapping coordinates for each of our models.

Textures and Assimp First off, we are going to need to change our Vertex struct: struct Vertex { GLfloat position[3]; GLfloat uv[2]; };

Textures and Assimp Why am I replacing GLfloat color[3] with GLfloat uv[2]? Textures specify two coordinates on an image with which to map that portion of the image to your object. The values in GLfloat uv[2] will always be in the range of 0.0-1.0 (inclusive).

Textures and Assimp In an aiMesh object, there is the following attribute: aiVector3D *mTextureCoords; Just like you used the mIndices array to offset into aiMesh’s mVertices array, you are going to use the mIndices array to offset into aiMesh’s mTextureCoords array. This data will go into your updated array of Vertex structs that will be sent to the GPU.

Textures and Assimp You can implement a test to check if the mesh has texture coordinates: mesh->HasTextureCoords(0); // returns a bool For obtaining the texture coordinates: aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[k]]; Where k is the appropriate offset into the mIndices array. vert[i].uv[0] = uv.x; // could also use pointers vert[i].uv[1] = uv.y; // here for offset Where i is the appropriate offset into your array of Vertex objects.

Textures and OpenGL At this point, we have coordinate data and texture data coupled together into an array of Vertex structs. Next, we’re going to use OpenGL functions to interact with our textures, but first, we need to use an image library to read our pictures.

Image Libraries Magick++ What we used last year, recommended FreeImagePlus Any other image library you want. Specify which library you chose in your README. Each library will have it’s own set of functions that you will need to utilize. Note: you will have to modify the LIBS section of your makefile and #include the correct libraries.

Textures and OpenGL Since we have modified our Vertex struct, which is being sent to the GPU (to the shaders), we are going to need to modify some shader code: In the vertex shader: Replace your attribute vec3 color variable with a attribute vec2 variable. Replace your varying vec3 color variable with a varying vec2 variable. Using these new variables, pass the texture to the fragment shader.

Textures and OpenGL Code modifications (continued): In the fragment shader: Replace your varying vec3 variable with a varying vec2 variable. Declare: uniform sampler2D gSampler; Inside main: Assign gl_FragColor to texture2D(gSampler, texture.xy), where texture is your new varying vec2 variable.

Textures and OpenGL Code modifications (continued): You are going to have to initialize a global GLint variable and use that variable to find the location of your new varying vec2 variable in the shaders (just like your old programs have done with loc_position and loc_color).

Textures and OpenGL Textures in OpenGL are somewhat analogous to VBO’s in the sense that they must be generated, bound, and activated (among a couple other things). You’re going to want to create a texture for each object (can have an array of textures). For generating a single texture (do this first; goes in your initialize() function): GLuint aTexture; glGenTextures(1, &aTexture);

Textures and OpenGL Binding textures (functions go in this order; also in initialize()): glActiveTexture(GL_TEXTURE0); Parameter will not change. glBindTexture(GL_TEXTURE_2D, aTexture); Second parameter is different if aTexture is an array of textures. Look up documentation.

Textures and OpenGL Binding textures (continued; still in this order): glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); Here, imageWidth and imageHeight are integers you obtain from the functions provided by your image library and imageData is an array of pixels that you create from your image library. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Textures and OpenGL Inside render(): You’ll want to call glActiveTexture(GL_TEXTURE0) and glBindTexture(GL_TEXTURE_2D, aTexture) so that you bind each texture to the corresponding object. You’ll also want to call glEnableVertexAttribArray() on your new GLint location and use glVertexAttribPointer() to describe the format of the the texture data to the GPU. All of this has been happening in your old programs.

References https://open.gl/textures We suggest reading this page. You’ll get filled in on what’s happening behind the scenes and you’ll better understand the functionality of the parameters in the previous functions.

Questions?