Setting up the Assimp library Creating the Mesh class and Model class How to load models in the game world using the Model class

Size: px
Start display at page:

Download "Setting up the Assimp library Creating the Mesh class and Model class How to load models in the game world using the Model class"

Transcription

1 The previous chapter was all about lighting up our game world. There, we discussed all the different types of light effects and learned how to include various types of light sources in the game world. In this chapter, we'll look at loading a model into our game world. We'll also learn how to set up Assimp, which is the model-loading library that we're going to use to load models into our game world. Assimp is an industry-standard library. It supports a wide array of models, from Wavefront OBJ to Collada. You'll also learn about how to create the Model class for the Assimp model loader; we can use that class to load our models into our game world. In this chapter, we'll cover the following topics: Setting up the Assimp library Creating the Mesh class and Model class How to load models in the game world using the Model class So, let's get started... We'll begin by learning about how to set up the Assimp library. Setting up the Assimp library Here we are going to cover how to set up Assimp, which is a model-loading library, on the Windows and macos platforms using Visual Studio and Xcode. In this section, we'll learn how to download the Assimp library and link it to our project to load models into our game. Let's get started by downloading the Assimp library.

2 Downloading the library Let's take a look at the following steps: 1. Download the Assimp library at assimp.org. 2. Go to the Downloads option. In here, you will get to see various versions of libraries; unless you need a specific version, such as an older version, it's best you download the latest version: Sometimes the version will be available on GitHub or SourceForge, which is fine. Whichever it is, just download the ZIP file that is available. It's always recommended to download the.zip file. [ 2 ]

3 3. Download CMake. CMake allows us to actually generate a Visual Studio solution that will generate the library and DLL files we need to link into our Visual Studio OpenGL project. 4. Go to / cmake. org/, then to Download options, and scroll down to the latest release: 5. Download either the 64-bit or 32-bit, as per your system requirements. If you are on a 64-bit machine, you can download 64 or 32. If you're on a 32-bit machine, you can only download the 32-bit version. Don't select the installer; just select the.zip extension. For this book, we have used the 64-bit version. You can download the 32-or 64-bit version; it doesn't matter as long as you have the right version. 6. Once you've downloaded the files, extract both folders. For Mac users, you can download the macos version of the CMake library. [ 3 ]

4 Setting up Assimp for the Windows platform In this section, we'll take a look at how to set up Assimp on the Windows platform. Adding libraries to the project folder Check out the following steps to link the libraries to our project: 1. After extracting the folders, open up the ASSIMP folder. In that folder, create a folder and name it build. 2. Open up the Command Prompt and type in cd, which is the command to change the directory. Press spacebar and then drag over the build folder that you created in the ASSIMP folder. You will be able to notice the following: 3. As you can see, the build folder is empty, but this is where our project will get generated for Assimp. Press Enter and you will get the following: 4. Go to the cmake folder and then to the bin folder. Then drag and drop cmake.exe to the Command Prompt, press spacebar, and then go back to the ASSIMP folder. 5. Within that folder, there is another assimp folder, which consists of various files and folders. Drag and drop this particular assimp folder into the Command Prompt and hit Enter. This will help build a Visual Studio project for us within the build folder. 6. Once the project has been successfully built, go to the build folder and then the Assimp.sln file. 7. Open up the Assimp.sln file in Visual Studio, right-click the ALL BUILD option in the Solution Explorer window, and then just click on the Build option: [ 4 ]

5 8. This will just take a moment or so. Wait for it to build your project successfully and then you'll be given a.dll and.lib file; we'll be hooking those up to our Visual Studio OpenGL project. 9. Once the project has been built successfully and the files have also been generated, you can close Visual Studio. 10. Go to the build folder, then go to code, and then go to the Debug folder. Within the Debug folder, you'll get the.dll and.lib files: 11. Copy all the files present in the Debug folder and then go to your Visual Studio OpenGL project, which is present in Windows folder. Create an External Libraries folder in it and go to the Windows folder. Within External Libraries, create a folder called assimp. Within the assimp folder, create a folder called lib and paste in all the files that we have copied. 12. Go to the assimp folder that we extracted. Within that folder, copy the include folder and paste it within External Libraries assimp. [ 5 ]

6 Linking libraries to the Visual Studio project Once you have added the libraries to the project folder, it's time to link these libraries to our project in Visual Studio, perform the following steps to do that: Open the Visual Studio project. Right-click on the name of your project in the Solution Explorer window. Go to Properties C/C++ General; then go to the Additional Include Directories option, click on the dropdown, then click on <Edit>. Click new icon and type in $(SolutionDir)/ExternalLibraries/ assimp/include: In the preceding screenshot, SolutionDir refers to this.sln file. [ 6 ]

7 In the preceding steps, we linked the libraries with the help of relative linking. If you are comfortable with absolute linking, you can use that. 4. To save some time, copy the path mentioned in the previous step, go to Properties Linker General, then click on Additional Library Directories, click on the dropdown, and then click on <Edit>. 5. Click new icon, paste the path into it, and make the following change to it: [ 7 ]

8 6. Go to Linker Input and click Additional Dependencies. Click the dropdown and then <Edit>. We need to specify our library file: 7. Click Apply and Click OK. Setting up Assimp for the Mac platform Let's take a look at how to set up Assimp for an Xcode project on the Mac platform. Perform the following steps: 1. Download the Assimp and CMake files. We saw how to download these files in the preceding section. Download and extract both files onto your system. 2. Open up CMake. Once it's open, you will get a window similar to this: [ 8 ]

9 3. Click on the Browse Source... button. Go to the location where you have downloaded and extracted the Assimp files and then press on the Open button. 4. Click on the Browse Build... button. Here you will have to provide the location where you want to build your libraries. [ 9 ]

10 5. Click the Configure button and a window will pop up, similar to the following screenshot: Here you will have to select your developing environment. For us it is Xcode, so we will select that. [ 10 ]

11 Linking up the libraries to the project In this section, we'll take a look at how to link up the libraries to our project on the Mac platform. To include the DYLIB in our exsisting project, we need to perform the following steps: 1. Go to main project folder on the Xcode, then go to Build Phases, and then to the Link Binary in the Libraries section by clicking on the + sign. 2. Click on the Add Other button. 3. Press Cmd + Shift + G, type in /usr/local/cellar, and click the Go button. 4. Go to the Assimp folder, choose the version folder that you've got. 5. Go to the lib folder and select libassimp dylib, or whatever version you have got, but remember to select the.dylib file only. 6. Click on the Open button. And that's how we include the DYLIB file in our existing project. With this last step, we are done with linking libraries to our project. Now we'll move on to creating the Mesh class. The Mesh class Now we are ready to create the Mesh class. The Mesh class is essentially a simple container that stores data, such as texture coordinates, vertices, and normals. We had studied this in the preceding section. Here, we are going to create a model object that will essentially be a container for several mesh objects. So, let's begin with creating the Mesh class. [ 11 ]

12 Creating the Mesh.h header file Let's take a look at the following steps to create Mesh.h header file: 1. On Xcode, head over to your OpenGL project, right-click on it, and select New File Select the header file and then click on the Next button. 3. Name the file Mesh.h and select OpenGL on Targets: 4. Click on the Create button and your empty header file will be created. [ 12 ]

13 Coding the Mesh.h header file In this section, we'll be coding our Mesh.h header files. Adding necessary header files Follow these steps to add header files to your code: 1. Add some header files to your code: #pragma once #include <string> #include <fstream> #include <sstream> #include <iostream> #include <vector> #include <GL/glew.h> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> 2. Add using namespace std to the code. Creating Vertex and Texture Struct Take a look at the steps to create Struct: 1. We'll be creating the Struct datatype, called Vertex, and we'll add the following lines of code to it: struct Vertex // Position glm::vec3 Position; // Normal glm::vec3 Normal; // TexCoords glm::vec2 TexCoords; ; [ 13 ]

14 2. Create another Struct, called Texture, and add the following lines of code to it: struct Texture GLuint id; string type; aistring path; ; Creating the Mesh class Now let's create the Mesh class. Follow these steps: 1. In the class Mesh, create a bunch of public variables: class Mesh public: /* Mesh Data */ vector<vertex> vertices; vector<gluint> indices; vector<texture> textures; 2. Create the constructor, called Mesh (), and to this add the following lines of code: // Constructor Mesh( vector<vertex> vertices, vector<gluint> indices, vector<texture> textures ) this->vertices = vertices; this->indices = indices; this->textures = textures; // Now that we have all the required data, set the vertex buffers //and its attribute pointers. this->setupmesh( ); In the preceding lines of code, with this->, we're just passing in the data for the vertices, the indices, and the textures, and assigning it to the mesh's variables so it knows what data it needs. Next, we added this->setupmesh( ); to set the vertex buffers and the attribute pointers. [ 14 ]

15 Defining the Draw method Now let's define the Draw method: 1. Create the Draw method, which will be public. We'll add the following lines of code to it: // Render the mesh void Draw( Shader shader ) // Bind appropriate textures GLuint diffusenr = 1; GLuint specularnr = 1; for( GLuint i = 0; i < this->textures.size( ); i++ ) glactivetexture( GL_TEXTURE0 + i ); // Active proper texture unit before binding // Retrieve texture number (the N in diffuse_texturen) stringstream ss; string number; string name = this->textures[i].type; if( name == "texture_diffuse" ) ss << diffusenr++; // Transfer GLuint to stream else if( name == "texture_specular" ) ss << specularnr++; // Transfer GLuint to stream number = ss.str( ); // Now set the sampler to the correct texture unit gluniform1i( glgetuniformlocation( shader.program, ( name + number ).c_str( ) ), i ); // And finally bind the texture glbindtexture( GL_TEXTURE_2D, this->textures[i].id ); 2. We've done the for loop. We've still got some code left to add to the Draw class. We need to set each mesh's shininess property to a default value. Default values are always good to prevent variables from messing up. So, we'll add the following lines of code: // Also set each mesh's shininess property to a default value (if you //want you could extend this to another mesh property and [ 15 ]

16 possibly //change this value) gluniform1f( glgetuniformlocation( shader.program, "material.shininess" ), 16.0f ); 3. Add the code to draw the mesh: // Draw mesh glbindvertexarray( this->vao ); gldrawelements( GL_TRIANGLES, this->indices.size( ), GL_UNSIGNED_INT, 0 ); glbindvertexarray( 0 ); 4. Set everything back to its default values once you're finished the configuration, (It's just a good practice): for ( GLuint i = 0; i < this->textures.size( ); i++ ) glactivetexture( GL_TEXTURE0 + i ); glbindtexture( GL_TEXTURE_2D, 0 ); Defining the private section of the Mesh class We're now done with the Draw method, and that's everything in the public section of the Mesh class. Next, we're going to define private section of the Mesh class: 1. Add a few variables: /* Render data */ GLuint VAO, VBO, EBO; We've looked at what all of these variables do in the initial chapters. If you're not too sure what these variables do, feel free to go back for a refresher. 2. To initialize all of the buffer objects and arrays, begin by typing void setupmesh( ). We called setupmesh in the constructor. This isn't something that the developer really would be calling manually. Once whatever is using the Mesh class as an object has constructed it, it will then call the SetupMesh method. 3. In setupmesh( ), we need to create the buffers and arrays, so we'll add the following lines of code: void setupmesh( ) // Create buffers/arrays glgenvertexarrays( 1, &this->vao ); [ 16 ]

17 glgenbuffers( 1, &this->vbo ); glgenbuffers( 1, &this->ebo ); glbindvertexarray( this->vao ); 4. Load the data into the vertex buffer, so we're going to add the following lines of code: glbindbuffer( GL_ARRAY_BUFFER, this->vbo ); // A great thing about structs is that their memory layout is sequential for all its items. // The effect is that we can simply pass a pointer to the struct and it translates perfectly to a glm::vec3/2 array which // again translates to 3/2 floats which translates to a byte array. glbufferdata( GL_ARRAY_BUFFER, this->vertices.size( ) * sizeof( Vertex ), &this->vertices[0], GL_STATIC_DRAW ); 5. Duplicate the preceding lines of code and make the following highlighted changes: glbindbuffer( GL_ELEMENT_ARRAY_BUFFER, this->ebo ); glbufferdata( GL_ELEMENT_ARRAY_BUFFER, this->indices.size( ) * sizeof( GLuint ), &this->indices[0], GL_STATIC_DRAW ); 6. We can move on to setting the vertex attribute pointers. The first one we are going to set up is the vertex positions: // Vertex Positions glenablevertexattribarray( 0 ); glvertexattribpointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof( Vertex ), ( GLvoid * )0 ); 7. Set up the vertex normals: // Vertex Normals glenablevertexattribarray( 1 ); glvertexattribpointer( 1, 3, GL_FLOAT, GL_FALSE, sizeof( Vertex ), ( GLvoid * )offsetof( Vertex, Normal ) ); 8. Set up texture co-ordinates: // Vertex Texture Coords glenablevertexattribarray(2); glvertexattribpointer( 2, 2, GL_FLOAT, GL_FALSE, sizeof( Vertex ), ( GLvoid * )offsetof( Vertex, TexCoords ) ); [ 17 ]

18 9. Unbind the vertex array: ; glbindvertexarray( 0 ); So, this is it for creating the mesh class. In the next section, we look at creating a Model class that will contain a number of these mesh classes. Getting rid of some old code As we will be working on the source code from Chapter 5, Types of Light Sources and Combining of Lights, there are some lines in the code that we need to get rid of from our main code. In this section, we won't be using our old lighting code or the cube code that we had discussed in the initial chapters. So, go to your main.cpp file and get rid of the build and compile-shader code, vertices-defining code, the code that defines cubepositions, all the attributes-defining code, and the SOIL code. Also get rid of the lightingshader.use () code. In the while loop, firstly, we need to get rid of the lightpos.x and lightpos.z code, and then we will get rid of all the lighting-related code until we define the SwapBuffer code. We'll also get rid of gldelete as we no longer will be deleting our arrays and buffers. Now that we have got rid of all the unwanted code, we'll get started with the our modelloading code. Modelloading In the previous sections, we went through the setup process of Assimp, and we also created the mesh class. Now, in this section, we are going to be looking at creating the Model class for the Assimp model loader, to start loading in models. The Model class basically consists of many meshes. We will now get started with creating our Model class. But before that, some information about the code files for this chapter would be useful; you can find the code files at the following link: / GitHub. com/ PacktPublishing/ Learn- OpenGL/ tree/ master/ Chapter07. [ 18 ]

19 The folder placed on this link consists of the res folder, in which there is a folder called models. This models folder consists of a lot of files related to the model that be we'll loading in our code. Creating the Model.h header file So, let's begin with creating our Model.h header file: 1. Right-click on your project folder. 2. Click on New File and click on the Header file option, because we will put the class within the header and we need to make sure that we add the header files to our target folder. We're going to name the header file Model.h and then click on the Create button: [ 19 ]

20 Coding the Model.h header file Now we'll begin coding our Model.h file, take a look at the following steps: 1. Add the basic things, such as strings and streams: #pragma once #include <string> #include <fstream> #include <sstream> #include <iostream> #include <map> #include <vector> 2. Include OpenGL, SOIL (which is a local library), the Assimp library, Mesh files, and other necessary files: #include <GL/glew.h> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include "SOIL2/SOIL2.h" #include <assimp/importer.hpp> #include <assimp/scene.h> #include <assimp/postprocess.h> #include "Mesh.h" OpenGL will assume we are using GLEW to load an extension, and not something such as glloadgen. But if we are using glloadgen, we need to replace it. 3. Add using namespace std;, and then we will also add the GLint TextureFromFile function: using namespace std; GLint TextureFromFile( const char *path, string directory ); 4. Create the Model class, wherein we will define our public section first with the Model constructor and then use the Draw method to draw the model: class Model public: /* Functions */ [ 20 ]

21 // Constructor, expects a filepath to a 3D model. Model( GLchar *path ) this->loadmodel( path ); // Draws the model, and thus all its meshes void Draw( Shader shader ) for ( GLuint i = 0; i < this->meshes.size( ); i++ ) this->meshes[i].draw( shader ); In the preceding code, we used the shader file. Then we iterated the for loop over the meshes and drew the meshes. Defining the private section of the Model class Next, we'll implement the arguments in private. Perform the following steps: 1. Create some variables in which we can store the Model data: private: /* Model Data */ vector<mesh> meshes; string directory; vector<texture> textures_loaded; // Stores all the textures loaded so far, optimization to make sure //textures aren't loaded more than once. 2. Create the loadmodel method that we called in the constructor. In this method, we need to read the file using Assimp, so we'll add the following lines of code: // Loads a model with supported ASSIMP extensions from file and stores the resulting meshes in the meshes vector. void loadmodel( string path ) // Read file via ASSIMP Assimp::Importer importer; const aiscene *scene = importer.readfile( path, aiprocess_triangulate aiprocess_flipuvs ); In the preceding code, we used Assimp, with the namespace as Importer. Then we had a constant aiscene, which is basically the assimp scene. [ 21 ]

22 3. Check whether there any errors while reading the file via assimp by adding the following lines of code: // Check for errors if(!scene scene->mflags == AI_SCENE_FLAGS_INCOMPLETE!scene- >mrootnode ) // if is Not Zero cout << "ERROR::ASSIMP:: " << importer.geterrorstring( ) << endl; return; 4. If there are no errors, we assume that the model has successfully loaded, and now we have to retrieve the directory path of the file path: // Retrieve the directory path of the filepath this->directory = path.substr( 0, path.find_last_of( '/' ) ); 5. Process all of Assimp's root nodes recursively: // Process ASSIMP's root node recursively this->processnode( scene->mrootnode, scene ); So, that is it for the load model method. 6. Implement the processnode method and add the following lines of code to it: void processnode( ainode* node, const aiscene* scene ) 7. Process each mesh located at the node: // Process each mesh located at the current node for ( GLuint i = 0; i < node->mnummeshes; i++ ) // The node object only contains indices to index the actual objects in the scene. // The scene contains all the data, node is just to keep stuff organized (like relations between nodes). aimesh* mesh = scene->mmeshes[node->mmeshes[i]]; this->meshes.push_back( this->processmesh( mesh, scene ) ); In the preceding code, the node object contains indices to index the actual objects in the scene. The scene contains all the data, and the node is just to keep relations between the nodes organized. [ 22 ]

23 8. Recursively process each of the children of the meshes if there are actually any: // After we've processed all of the meshes (if any) we then recursively process each of the children nodes for ( GLuint i = 0; i < node->mnumchildren; i++ ) this->processnode( node->mchildren[i], scene ); 9. And that s all for processnode. We will now create the processmesh method, which actually returns a mesh. The first thing to do in this method is to create some variables, which will include the vertices, the indices, and the textures: all the basic stuff that we have pretty much done before: Mesh processmesh( aimesh *mesh, const aiscene *scene ) // Data to fill vector<vertex> vertices; vector<gluint> indices; vector<texture> textures; 10. We'll walk through each of the mesh's vertices now, and then we'll want to loop over it: // Walk through each of the mesh's vertices for ( GLuint i = 0; i < mesh->mnumvertices; i++ ) Vertex vertex; 11. In the loop, declare a placeholder vector, since Assimp uses its own vector class and doesn't directly convert to it: glm::vec3 vector; 12. And for the positions, in the for loop, we are going to set the position as follows : // Positions vector.x = mesh->mvertices[i].x; vector.y = mesh->mvertices[i].y; vector.z = mesh->mvertices[i].z; vertex.position = vector; [ 23 ]

24 13. And,similarly, we need to mention the normals as follows : // Normals vector.x = mesh->mnormals[i].x; vector.y = mesh->mnormals[i].y; vector.z = mesh->mnormals[i].z; vertex.normal = vector; 14. Check the texture coordinates. To do that, add the following code. Check, with the help of the if statement, whether the mesh consists of texture coordinates or not. If not, we'll implement the else condition: // Texture Coordinates if( mesh->mtexturecoords[0] ) // Does the mesh contain texture coordinates? glm::vec2 vec; vec.x = mesh->mtexturecoords[0][i].x; vec.y = mesh->mtexturecoords[0][i].y; vertex.texcoords = vec; else vertex.texcoords = glm::vec2( 0.0f, 0.0f ); A vertex can contain up to eight different texture coordinates. We thus make the assumption that we won't use models where a vertex can have multiple texture coordinates; we always take the first set as zero, so we added mtexturecoords[0]. In the else statement, we just assign the default values of 0.0f and 0.0f if the mesh doesn't have any texture coordinates. 15. Push back the vertex that we have calculated: vertices.push_back( vertex ); 16. Walk through each of the faces in the mesh and retrieve the corresponding vertex indices. Add a for loop to our code and initialize it, and then inside the for loop, create an Assimp face variable: // Now wak through each of the mesh's faces (a face is a mesh its triangle) and retrieve the corresponding vertex indices. for ( GLuint i = 0; i < mesh->mnumfaces; i++ ) aiface face = mesh->mfaces[i]; [ 24 ]

25 17. Inside this loop, we'll add another for loop to retrieve all indices of the face variable and store them in the indices vector: for ( GLuint j = 0; j < face.mnumindices; j++ ) indices.push_back( face.mindices[j] ); 18. Process the material, because so far we've just been processing the meshes and the vertices. Add an if statement to the code to check whether the mmaterialindex mesh is greater than 0: // Process materials if( mesh->mmaterialindex >= 0 ) aimaterial* material = scene->mmaterials[mesh->mmaterialindex]; 19. Assume a convention for the sampler name in the shaders. Each diffuse texture should be named as texture_diffusen, where N is basically the sequential number ranging from 1 to the max sampler number, with the same applying to the other texture. So, basically, diffuse is texture_diffusen, specular is texture_specularn, and normal is texture_normaln. In order to handle the diffuse map, perform the following: // Diffuse maps vector<texture> diffusemaps = this->loadmaterialtextures( material, aitexturetype_diffuse, "texture_diffuse" ); textures.insert( textures.end( ), diffusemaps.begin( ), diffusemaps.end( ) ); 20. To handle the specular maps, perform: // Specular maps vector<texture> specularmaps = this->loadmaterialtextures( material, aitexturetype_specular, "texture_specular" ); textures.insert( textures.end( ), specularmaps.begin( ), specularmaps.end( ) ); 21. So, outside of this if statement, we're going to return a mesh object that is extracted from the mesh data: // Return a mesh object created from the extracted mesh data return Mesh( vertices, indices, textures ); [ 25 ]

26 22. Load the material textures, which is going to be returning a vector of textures. This will check all material textures of a given type and load the textures if they're not loaded already. The required info is returned as a texture struct: vector<texture> loadmaterialtextures( aimaterial *mat, aitexturetype type, string typename ) vector<texture> textures; 23. Loop over the material that we created here: for ( GLuint i = 0; i < mat->gettexturecount( type ); i++ ) aistring str; mat->gettexture( type, i, &str ); 24. Create a variable named GLboolean and set it to false to check whether the texture was loaded before. If so, continue to the next iteration skip loading a new texture, create a for loop, and push in the texture that has been loaded: GLboolean skip = false; for ( GLuint j = 0; j < textures_loaded.size( ); j++ ) 25. Check the if condition to see whether the texture has been loaded and returns the textures: if( textures_loaded[j].path == str ) textures.push_back( textures_loaded[j] ); skip = true; // A texture with the same fil epath has already been loaded, continue to next one. (optimization) break; 26. After the for loop, we are going to check whether the texture has been loaded, and load it if it hasn't been already: if(!skip ) // If texture hasn't been loaded already, load it Texture texture; texture.id = TextureFromFile( str.c_str( ), this->directory ); texture.type = typename; texture.path = str; textures.push_back( texture ); [ 26 ]

27 this->textures_loaded.push_back( texture ); // Store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures. ; return textures; 27. If you remember, right at the top, we created a function declaration but we didn't implement it anywhere in the code. So, we're going to implement that now. Generate a texture ID, and load the texture data appropriately: GLint TextureFromFile( const char *path, string directory ) //Generate texture ID and load texture data string filename = string( path ); filename = directory + '/' + filename; GLuint textureid; glgentextures( 1, &textureid ); int width, height; 28. We need an unsigned character that will store the image data: unsigned char *image = SOIL_load_image( filename.c_str( ), &width, &height, 0, SOIL_LOAD_RGB ); 29. Assign a texture to the particular ID. To do that, we need to bind textureid to texture2d: // Assign texture to ID glbindtexture( GL_TEXTURE_2D, textureid ); glteximage2d( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image ); 30. Generate the Mipmap for the preceding texture ID: glgeneratemipmap( GL_TEXTURE_2D ); [ 27 ]

28 31. Specify the parameters: // Parameters 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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glbindtexture( GL_TEXTURE_2D, 0 ); SOIL_free_image_data( image ); return textureid; And now we are done coding our Model.h file. Creating new shaders Let's create new shaders for model loading by following below-mentioned steps: 1. Go to the shaders folder and create a couple of new shaders. We will duplicate the shaders from what we've already got. We then rename them to modelloading.vs and modelloading.frag. 2. Go to the vertex shader, modelloading.vs, and type the following highlighted terms: #version 330 core layout ( location = 0 ) in vec3 position; layout ( location = 1 ) in vec3 normal; layout ( location = 2 ) in vec2 texcoords; out vec2 TexCoords; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main( ) gl_position = projection * view * model * vec4( position, 1.0f ); TexCoords = texcoords; [ 28 ]

29 3. For the fragment shader, take a look at the following highlighted code and carry out the necessary changes: #version 330 core in vec2 TexCoords; out vec4 color; uniform sampler2d texture_diffuse; void main( ) color = vec4( texture( texture_diffuse, TexCoords )); We're done with creating new shaders for model loading. So, now we are ready to actually load our model. So, we will go to main.cpp and carry out certain modifications to it. Loading the model in the main code Let's take a look at following steps to understand how to load the model in the main code: 1. Include the new Model.h header file in our existing code: #include "Model.h" 2. Before our projection matrix code, we need to add code to set up and compile our shaders: // Setup and compile our shaders Shader shader( "res/shaders/modelloading.vs", "res/shaders/modelloading.frag" ); 3. Load the model: // Load models Model ourmodel( "res/models/nanosuit.obj" ); This nanosuit.obj file consists of information about our model that we'll be loading in our game world. [ 29 ]

30 4. In the while loop, after we've defined glclear, we want to add code to use the shader: shader.use( ); 5. Create a ViewMatrix: glm::mat4 view = camera.getviewmatrix( ); gluniformmatrix4fv( glgetuniformlocation( shader.program, "projection" ), 1, GL_FALSE, glm::value_ptr( projection ) ); gluniformmatrix4fv( glgetuniformlocation( shader.program, "view" ), 1, GL_FALSE, glm::value_ptr( view ) ); 6. Draw the loaded model: // Draw the loaded model glm::mat4 model; model = glm::translate( model, glm::vec3( 0.0f, -1.75f, 0.0f ) ); // Translate it down a bit so it's at the center of the scene model = glm::scale( model, glm::vec3( 0.2f, 0.2f, 0.2f ) ); // It's a bit too big for our scene, so scale it down gluniformmatrix4fv( glgetuniformlocation( shader.program, "model" ), 1, GL_FALSE, glm::value_ptr( model ) ); ourmodel.draw( shader ); And now we are ready to run the code and load the model in our game world. If your code complies without any errors, you will get to see the following output on your screen: [ 30 ]

31 We can move this model around using our camera class: [ 31 ]

32 So, that is it for model loading. Now that you've got this code all sorted, you can start loading a bunch of other models. It is recommended going to the Assimp website to see what models they support. There's just a whole heap of model types they support, and it's fantastic. There's one more thing that we can do with the model: we can try to implement the wireframe for our model. So, after we define the model-loading code, add the following line to set the polygon mode for our model: Model ourmodel( "res/models/nanosuit.obj" ); glpolygonmode( GL_FRONT_AND_BACK, GL_LINE ); Save this code and you'll get the wireframe version of our model: You can observe that the wireframe is basically just the lines the polygons that make up our shape. You can see all the different intricacies of our shape. [ 32 ]

33 Summary In this chapter, we learned how to set up Assimp (Open Asset Import Library) on Windows using CMake for all our model-loading needs. We also covered setting up the Assimp library on macos X. Then we created a cross-platform Mesh class and the Mesh.h header file. We also explored how to load a 3D model into our game and generated the wireframe of our model. [ 33 ]

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 7 Part 2 Texture Mapping in OpenGL Matt Burlick - Drexel University - CS 432 1 Topics Texture Mapping in OpenGL Matt Burlick - Drexel University - CS 432 2

More information

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

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Texture Mapping CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 1 Objectives Introduce Mapping Methods - Texture Mapping - Environment Mapping - Bump Mapping Consider

More information

CSE 167. Discussion 03 ft. Glynn 10/16/2017

CSE 167. Discussion 03 ft. Glynn 10/16/2017 CSE 167 Discussion 03 ft Glynn 10/16/2017 Announcements - Midterm next Tuesday(10/31) - Sample midterms are up - Project 1 late grading until this Friday - You will receive 75% of the points you ve earned

More information

Tutorial 1: Your First Triangle!

Tutorial 1: Your First Triangle! Tutorial 1: Your First Triangle! Summary For your first dabble in OpenGL, you are going to create the graphics programming equivalent of Hello World - outputting a single coloured triangle. It doesn t

More information

Discussion 3. PPM loading Texture rendering in OpenGL

Discussion 3. PPM loading Texture rendering in OpenGL Discussion 3 PPM loading Texture rendering in OpenGL PPM Loading - Portable PixMap format 1. 2. Code for loadppm(): http://ivl.calit2.net/wiki/images/0/09/loadppm.txt ppm file format: Header: 1. P6: byte

More information

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation Lecture 19: OpenGL Texture Mapping CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives Introduce the OpenGL texture functions and options

More information

Lighting and Texturing

Lighting and Texturing Lighting and Texturing Michael Tao Michael Tao Lighting and Texturing 1 / 1 Fixed Function OpenGL Lighting Need to enable lighting Need to configure lights Need to configure triangle material properties

More information

Tutorial 3: Texture Mapping

Tutorial 3: Texture Mapping Tutorial 3: Texture Mapping Summary In this tutorial, you are going to learn about texture mapping, by performing some texture mapping operations on the triangle you ve been using in the previous tutorials.

More information

Tutorial 12: Real-Time Lighting B

Tutorial 12: Real-Time Lighting B Tutorial 12: Real-Time Lighting B Summary The last tutorial taught you the basics of real time lighting, including using the normal of a surface to calculate the diffusion and specularity. Surfaces are

More information

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

CS452/552; EE465/505. Texture Mapping in WebGL CS452/552; EE465/505 Texture Mapping in WebGL 2-26 15 Outline! Texture Mapping in WebGL Read: Angel, Chapter 7, 7.3-7.5 LearningWebGL lesson 5: http://learningwebgl.com/blog/?p=507 Lab3 due: Monday, 3/2

More information

CS475/CS675 - Computer Graphics. OpenGL Drawing

CS475/CS675 - Computer Graphics. OpenGL Drawing CS475/CS675 - Computer Graphics OpenGL Drawing What is OpenGL? Open Graphics Library API to specify geometric objects in 2D/3D and to control how they are rendered into the framebuffer. A software interface

More information

Overview. By end of the week:

Overview. By end of the week: Overview By end of the week: - Know the basics of git - Make sure we can all compile and run a C++/ OpenGL program - Understand the OpenGL rendering pipeline - Understand how matrices are used for geometric

More information

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

CS452/552; EE465/505. Image Processing Frame Buffer Objects CS452/552; EE465/505 Image Processing Frame Buffer Objects 3-12 15 Outline! Image Processing: Examples! Render to Texture Read: Angel, Chapter 7, 7.10-7.13 Lab3 new due date: Friday, Mar. 13 th Project#1

More information

CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE

CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE CS 548: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE INTRODUCTION We re going to talk a little bit about the structure and logic of a basic, interactive OpenGL/GLUT

More information

Tutorial 04. Harshavardhan Kode. September 14, 2015

Tutorial 04. Harshavardhan Kode. September 14, 2015 Tutorial 04 Harshavardhan Kode September 14, 2015 1 About This tutorial an extension of the Tutorial 03. So you might see quite a lot similarities. The following things are new. A Plane is added underneath

More information

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics CS4621/5621 Fall 2015 Basics of OpenGL/GLSL Textures Basics Professor: Kavita Bala Instructor: Nicolas Savva with slides from Balazs Kovacs, Eston Schweickart, Daniel Schroeder, Jiang Huang and Pramook

More information

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

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 CSE 167: Introduction to Computer Graphics Lecture #7: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 Announcements Project 2 due Friday 4/22 at 2pm Midterm #1 on

More information

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov CSE 4431/5331.03M Advanced Topics in 3D Computer Graphics TA: Margarita Vinnikov mvinni@cse.yorku.ca Goals of any 3d application is speed. You should always limit the amount of polygons actually rendered

More information

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports Computação Gráfica Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre Chap. 4 Windows and Viewports Outline : Basic definitions in 2D: Global coordinates (scene domain): continuous domain

More information

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

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017 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

More information

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

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE OPENGL STATE MACHINE OpenGL state system or state machine Has list of all current state values called state

More information

Computergraphics Exercise 15/ Shading & Texturing

Computergraphics Exercise 15/ Shading & Texturing Computergraphics Exercise 15/16 3. Shading & Texturing Jakob Wagner for internal use only Shaders Vertex Specification define vertex format & data in model space Vertex Processing transform to clip space

More information

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40) 11(40) Information Coding / Computer Graphics, ISY, LiTH OpenGL where it fits what it contains how you work with it 11(40) OpenGL The cross-platform graphics library Open = Open specification Runs everywhere

More information

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York Building Models Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Introduce simple data structures for building polygonal models - Vertex lists - Edge lists Deprecated

More information

3d Programming I. Dr Anton Gerdelan

3d Programming I. Dr Anton Gerdelan 3d Programming I Dr Anton Gerdelan gerdela@scss.tcd.ie 3d Programming 3d programming is very difficult 3d programming is very time consuming 3d Programming Practical knowledge of the latest, low-level

More information

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

-=Catmull's Texturing=1974. Part I of Texturing -=Catmull's Texturing=1974 but with shaders Part I of Texturing Anton Gerdelan Textures Edwin Catmull's PhD thesis Computer display of curved surfaces, 1974 U.Utah Also invented the z-buffer / depth buffer

More information

Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader

Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader University of Liège Departement of Aerospace and Mechanical engineering Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader Exercise 1: Introduction to shaders (Folder square in archive

More information

CPSC 436D Video Game Programming

CPSC 436D Video Game Programming CPSC 436D Video Game Programming OpenGL/Shaders Opengl RENDERING PIPELINE Copyright: Alla Sheffer 1 Opengl RENDERING PIPELINE C/C++ OpenGL GLSL (automatic) (automatic) GLSL (automatic) opengl Low-level

More information

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

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders Prateek Shrivastava CS12S008 shrvstv@cse.iitm.ac.in 1 GLSL Data types Scalar types: float, int, bool Vector

More information

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Building Models CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 1 Objectives Introduce simple data structures for building polygonal models - Vertex lists - Edge

More information

CS179: GPU Programming

CS179: GPU Programming CS179: GPU Programming Lecture 4: Textures Original Slides by Luke Durant, Russel McClellan, Tamas Szalay Today Recap Textures What are textures? Traditional uses Alternative uses Recap Our data so far:

More information

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

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping CISC 3620 Lecture 7 Lighting and shading Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping Exam results Grade distribution 12 Min: 26 10 Mean: 74 8 Median:

More information

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT Dr Franck P. Vidal 4 th September 2014 1 Contents Table of contents 2 List of figures 3 List of listings 3 1 Introduction 4

More information

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University Graphics Programming Computer Graphics, VT 2016 Lecture 2, Chapter 2 Fredrik Nysjö Centre for Image analysis Uppsala University Graphics programming Typically deals with How to define a 3D scene with a

More information

Introduction to Computer Graphics with WebGL

Introduction to Computer Graphics with WebGL Introduction to Computer Graphics with WebGL Ed Angel The Mandelbrot Set Fractals Fractal (fractional geometry) objects generate some of the most complex and beautiful graphics - The mathematics describing

More information

Texture Mapping. Mike Bailey.

Texture Mapping. Mike Bailey. Texture Mapping 1 Mike Bailey mjb@cs.oregonstate.edu This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License TextureMapping.pptx The Basic Idea

More information

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY 1(61) Information Coding / Computer Graphics, ISY, LiTH TSBK 07 Computer Graphics Ingemar Ragnemalm, ISY 1(61) Lecture 6 Texture mapping Skyboxes Environment mapping Bump mapping 2(61)2(61) Texture mapping

More information

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM Starting out with OpenGL ES 3.0 Jon Kirkham, Senior Software Engineer, ARM Agenda Some foundational work Instanced geometry rendering Uniform Buffers Transform feedback ETC2 Texture formats Occlusion Queries

More information

Shaders. Slide credit to Prof. Zwicker

Shaders. Slide credit to Prof. Zwicker Shaders Slide credit to Prof. Zwicker 2 Today Shader programming 3 Complete model Blinn model with several light sources i diffuse specular ambient How is this implemented on the graphics processor (GPU)?

More information

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

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015 Buffers 1 Objectives Introduce additional WebGL buffers Reading and writing buffers Buffers and Images 2 Buffer Define a buffer by its spatial resolution (n x m) and its depth (or precision) k, the number

More information

GLSL Overview: Creating a Program

GLSL Overview: Creating a Program 1. Create the OpenGL application GLSL Overview: Creating a Program Primarily concerned with drawing Preferred approach uses buffer objects All drawing done in terms of vertex arrays Programming style differs

More information

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 2 Part 1 Primitives and Buffers Matt Burlick - Drexel University - CS 432 1 Rendering in OpenGL Ok, so now we want to actually draw stuff! OpenGL (like most

More information

Geometry Shaders. And how to use them

Geometry Shaders. And how to use them Geometry Shaders And how to use them OpenGL Pipeline (part of it) Vertex data Vertex shader Vertices Primitives Geometry shader Primitives Fragments Fragment shader Color Depth Stencil Vertex Data Attributes

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program Comp 410/510 Computer Graphics Spring 2017 Programming with OpenGL Part 2: First Program Objectives Refine the first program Introduce a standard program structure - Initialization Program Structure Most

More information

COMP371 COMPUTER GRAPHICS

COMP371 COMPUTER GRAPHICS COMP371 COMPUTER GRAPHICS SESSION 12 PROGRAMMABLE SHADERS Announcement Programming Assignment #2 deadline next week: Session #7 Review of project proposals 2 Lecture Overview GPU programming 3 GPU Pipeline

More information

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

WebGL A quick introduction. J. Madeira V. 0.2 September 2017 WebGL A quick introduction J. Madeira V. 0.2 September 2017 1 Interactive Computer Graphics Graphics library / package is intermediary between application and display hardware Application program maps

More information

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

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction TEXTURE MAPPING 1 OUTLINE Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction 2 BASIC STRAGEGY Three steps to applying a texture 1. specify the texture

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders Comp 410/510 Computer Graphics Spring 2018 Programming with OpenGL Part 3: Shaders Objectives Basic shaders - Vertex shader - Fragment shader Programming shaders with GLSL Finish first program void init(void)

More information

Lecture 07: Buffers and Textures

Lecture 07: Buffers and Textures Lecture 07: Buffers and Textures CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA October 26, 2010 OpenGL Pipeline Today s Focus Pixel Buffers: read and write image data to and from

More information

Rendering Objects. Need to transform all geometry then

Rendering Objects. Need to transform all geometry then Intro to OpenGL Rendering Objects Object has internal geometry (Model) Object relative to other objects (World) Object relative to camera (View) Object relative to screen (Projection) Need to transform

More information

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

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 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 calls to load vertex data to vertex buffers calls to load

More information

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

Fog example. Fog is atmospheric effect. Better realism, helps determine distances Fog example Fog is atmospheric effect Better realism, helps determine distances Fog Fog was part of OpenGL fixed function pipeline Programming fixed function fog Parameters: Choose fog color, fog model

More information

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques Texture Mapping Textures The realism of an image is greatly enhanced by adding surface textures to the various faces of a mesh object. In part a) images have been pasted onto each face of a box. Part b)

More information

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

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005 General Purpose computation on GPUs Liangjun Zhang 2/23/2005 Outline Interpretation of GPGPU GPU Programmable interfaces GPU programming sample: Hello, GPGPU More complex programming GPU essentials, opportunity

More information

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2) Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Modeling a Cube In 3D, declare vertices as (x,y,z)

More information

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1) Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) OpenGL/GLUT Installation OpenGL: Specific

More information

COSC342: Computer Graphics

COSC342: Computer Graphics COSC342: Computer Graphics 2017 Tutorial C++ Recap Stefanie Zollmann COMPUTER SCIENCE C++ CLASSES class Camera{ public: //! Default constructor /*! Setting up default camera. */ Camera(); /*! Set position.

More information

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 2 Part 2 Introduction to Shaders Matt Burlick - Drexel University - CS 432 1 Shaders To understand shaders, let s look at the graphics pipeline again The job

More information

Lab 2-3D Transformations and Vertex Shaders

Lab 2-3D Transformations and Vertex Shaders Lab 2-3D Transformations and Vertex Shaders Support code: /course/cs1230/src/labs/lab02 Demo: /course/cs1230/bin/cs1230_lab02_demo Intro Last week you learned how to draw 2D shapes in OpenGL using VBOs

More information

Introductory Seminar

Introductory Seminar EDAF80 Introduction to Computer Graphics Introductory Seminar OpenGL & C++ Michael Doggett 2017 C++ slides by Carl Johan Gribel, 2010-13 Today Lab info OpenGL C(++)rash course Labs overview 5 mandatory

More information

Lab 1: First Steps in C++ - Eclipse

Lab 1: First Steps in C++ - Eclipse Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the

More information

CS452/552; EE465/505. Review & Examples

CS452/552; EE465/505. Review & Examples CS452/552; EE465/505 Review & Examples 2-05 15 Outline Review and Examples:! Shaders, Buffers & Binding! Example: Draw 3 Triangles Vertex lists; gl.drawarrays( ) Edge lists: gl.drawelements( )! Example:

More information

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

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15 Min H. Kim KAIST School of Computing Materials SUMMARY 2 1 Light blob from PVC plastic Recall: Given any vector w (not necessarily of

More information

An Introduction to OpenGL Programming

An Introduction to OpenGL Programming An Introduction to OpenGL Programming Ed Angel University of New Mexico Dave Shreiner ARM, Inc. With some changes by João Madeiras Pereira What Is OpenGL? OpenGL is a computer graphics rendering application

More information

Vertex Buffer Objects

Vertex Buffer Objects 1 Vertex Buffer Objects This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License Mike Bailey mjb@cs.oregonstate.edu VertexBuffers.pptx Vertex Buffer

More information

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea 1 Vertex Buffer Objects This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License Mike Bailey mjb@cs.oregonstate.edu VertexBuffers.pptx Vertex Buffer

More information

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

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018 CSE 167: Introduction to Computer Graphics Lecture #7: Textures Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018 Announcements Project 2 due this Friday at 2pm Grading in

More information

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

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒 三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒 1 In this chapter, you will learn The basics of texture mapping Texture coordinates Texture objects and texture binding Texture specification

More information

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

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University Texture Mapping Computer Graphics, 2015 Lecture 9 Johan Nysjö Centre for Image analysis Uppsala University What we have rendered so far: Looks OK, but how do we add more details (and colors)? Texture mapping

More information

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

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실. Graphics Texture Mapping 고려대학교컴퓨터그래픽스연구실 3D Rendering Pipeline 3D Primitives 3D Modeling Coordinates Model Transformation 3D World Coordinates Lighting 3D World Coordinates Viewing Transformation 3D Viewing

More information

I think this assignment should have 8 objectives but we should still mark it out of 10. The Mean TA.

I think this assignment should have 8 objectives but we should still mark it out of 10. The Mean TA. Chapter 1 CS488/688 F17 A1: Introduction I think this assignment should have 8 objectives but we should still mark it out of 10. The Mean TA. This assignment is due Thursday, September 28th [Week 3]. 1.1

More information

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL Preview CS770/870 Spring 2017 Open GL Shader Language GLSL Review traditional graphics pipeline CPU/GPU mixed pipeline issues Shaders GLSL graphics pipeline Based on material from Angel and Shreiner, Interactive

More information

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL CS770/870 Spring 2017 Open GL Shader Language GLSL Based on material from Angel and Shreiner, Interactive Computer Graphics, 6 th Edition, Addison-Wesley, 2011 Bailey and Cunningham, Graphics Shaders 2

More information

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel, EDAF80 Introduction to Computer Graphics Seminar 3 Shaders Michael Doggett 2017 Slides by Carl Johan Gribel, 2010-13 Today OpenGL Shader Language (GLSL) Shading theory Assignment 3: (you guessed it) writing

More information

First, let's make sure we have all of the starter code downloaded. MAC (Go to the second part of the tutorial if you are using windows)

First, let's make sure we have all of the starter code downloaded. MAC (Go to the second part of the tutorial if you are using windows) CSE 167 HW 0 - Due Thur. Jan 18th at 11:59 p.m. This homework will help you set up OpenGL on your computer. First, let's make sure we have all of the starter code downloaded. https://github.com/ht413/cse167startercode

More information

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

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access Stored Texture Shaders Preparing for Texture Access These steps are the same when using a shader as when using fixed functionality Make a specific texture unit active by calling glactivetexture Create

More information

The Stack, Free Store, and Global Namespace

The Stack, Free Store, and Global Namespace Pointers This tutorial is my attempt at clarifying pointers for anyone still confused about them. Pointers are notoriously hard to grasp, so I thought I'd take a shot at explaining them. The more information

More information

Stored Texture Shaders

Stored Texture Shaders Stored Texture Shaders 157 Preparing for Texture Access These steps are the same when using a shader as when using fixed functionality Make a specific texture unit active by calling glactivetexture Create

More information

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

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects CSCI 420 Computer Graphics Lecture 4 Shaders Jernej Barbic University of Southern California Shading Languages GLSL Vertex Array Objects Vertex Shader Fragment Shader [Angel Ch. 1, 2, A] Introduction The

More information

INF3320 Computer Graphics and Discrete Geometry

INF3320 Computer Graphics and Discrete Geometry INF3320 Computer Graphics and Discrete Geometry Texturing Christopher Dyken Martin Reimers 06.10.2010 Page 1 Texturing Linear interpolation Real Time Rendering: Chapter 5: Visual Appearance Chapter 6:

More information

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer Best practices for effective OpenGL programming Dan Omachi OpenGL Development Engineer 2 What Is OpenGL? 3 OpenGL is a software interface to graphics hardware - OpenGL Specification 4 GPU accelerates rendering

More information

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J. CS 380 Introduction to Computer Graphics LAB (1) : OpenGL Tutorial 2018. 03. 05 Reference : Foundations of 3D Computer Graphics, Steven J. Gortler Goals Understand OpenGL pipeline Practice basic OpenGL

More information

3D Modeling. 3D Modeling 1

3D Modeling. 3D Modeling 1 3D Modeling 3D Modeling 1 Virtual enviroments can be populated with "models" as well as regular geometries (glut shapes, glu quadrics, gl primitives). Models are: collections of primitives often in a display

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

Arduino IDE Friday, 26 October 2018

Arduino IDE Friday, 26 October 2018 Arduino IDE Friday, 26 October 2018 12:38 PM Looking Under The Hood Of The Arduino IDE FIND THE ARDUINO IDE DOWNLOAD First, jump on the internet with your favorite browser, and navigate to www.arduino.cc.

More information

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors) Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Announcements Sample exam 1

More information

EECS 487: Interactive Computer Graphics

EECS 487: Interactive Computer Graphics Integrating GLSL with OpenGL EECS 487: Interactive Computer Graphics Lecture 19: Integrating shaders with OpenGL program Vertex-array objects with shaders Miscellaneous shader related stuff Integrating

More information

Tutorial 4: Depth and Transparency

Tutorial 4: Depth and Transparency Tutorial 4: Depth and Transparency Summary In this tutorial, you are going to learn about how OpenGL determines which objects are in front of others in a scene - it s not as easy at it seems! Alpha blending

More information

Computer graphic -- Programming with OpenGL I

Computer graphic -- Programming with OpenGL I Computer graphic -- Programming with OpenGL I A simple example using OpenGL Download the example code "basic shapes", and compile and run it Take a look at it, and hit ESC when you're done. It shows the

More information

Programming with OpenGL Complete Programs Objectives Build a complete first program

Programming with OpenGL Complete Programs Objectives Build a complete first program Programming with OpenGL Complete Programs Objectives Build a complete first program Introduce shaders Introduce a standard program structure Simple viewing Two-dimensional viewing as a special case of

More information

Methodology for Lecture

Methodology for Lecture Basic Geometry Setup Methodology for Lecture Make mytest1 more ambitious Sequence of steps Demo Review of Last Demo Changed floor to all white, added global for teapot and teapotloc, moved geometry to

More information

Sign up for crits! Announcments

Sign up for crits! Announcments Sign up for crits! Announcments Reading for Next Week FvD 16.1-16.3 local lighting models GL 5 lighting GL 9 (skim) texture mapping Modern Game Techniques CS248 Lecture Nov 13 Andrew Adams Overview The

More information

Here's how you declare a function that returns a pointer to a character:

Here's how you declare a function that returns a pointer to a character: 23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is

More information

Computer Graphics (CS 4731) & 2D Graphics Systems

Computer Graphics (CS 4731) & 2D Graphics Systems Computer Graphics (CS 4731) Lecture 4: Shader Setup & 2D Graphics Systems Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Recall: OpenGL Program: Shader Setup initshader(

More information

[175 points] The purpose of this assignment is to give you practice with shaders in OpenGL.

[175 points] The purpose of this assignment is to give you practice with shaders in OpenGL. CPSC 441 Computer Graphics Assignment 5 due 11/20/18 (11:59 p.m.) [175 points] The purpose of this assignment is to give you practice with shaders in OpenGL. Part 1: First, download and get the code itself

More information

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 [talking head] This lecture we study theory design and implementation. Programmers have two roles to play here. In one role, they

More information

Clickteam Fusion 2.5 Creating a Debug System - Guide

Clickteam Fusion 2.5 Creating a Debug System - Guide INTRODUCTION In this guide, we will look at how to create your own 'debug' system in Fusion 2.5. Sometimes when you're developing and testing a game, you want to see some of the real-time values of certain

More information

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1 Chapter 8 Three-Dimensional Object Representations 8-1 8.1 Overview The main goal of three-dimensional computer graphics is to generate two-dimensional images of a scene or of an object based on a a description

More information

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

Texture Mapping. Texture Mapping. Map textures to surfaces. Trompe L Oeil ( Deceive the Eye ) The texture. Texture map CSCI 42 Computer Graphic Lecture 2 Texture Mapping A way of adding urface detail Texture Mapping Jernej Barbic Univerity of Southern California Texture Mapping + Shading Filtering and Mipmap Non-color

More information

Developing a Comprehensive Software Toolkit for Creating Digital Mosaic Artwork

Developing a Comprehensive Software Toolkit for Creating Digital Mosaic Artwork City University of New York (CUNY) CUNY Academic Works Master's Theses City College of New York 2012 Developing a Comprehensive Software Toolkit for Creating Digital Mosaic Artwork Dmitry Bosikov CUNY

More information