main-practice3

Practice Program 3 - Shaders and Textures

For the final project, you are going to need to be able to use textures and shaders.

In order to use textures or shaders, you both need to understand them, as well as be able to deal with all of the program mechanics involved in using them in an OpenGL program. We’ll make the latter part easier for you (if you want) by providing libraries that make it easy to load shaders and textures.

Before the project, we want to make sure that everyone can get shaders and textures to work. Once you understand the mechanics, you can focus on making effective use of texture and shaders in your project.

So, for this practice assignment, you need to create a program that

  1. loads in a texture from a file and displays it on a 3D object
  2. loads in a vertex and fragment shader and displays it on a 3D object

We don’t care what the texture is, what the object is, how boring things are. Just that you are able to get a program like this to compile and run.

In fact, we’ll even give you a solution. In this zip file, there’s a program that satisfies the requirements. All you need to do is download it, compile it, and run it. Then try to modify the program to show a different texture, and write your own shader (again, it doesn’t have to do much - just to make sure you understand enough about GLSL to change the shader).

You are, of course, welcome to make something cooler than the simple cube in the sample.

All you need to do for this assignment is to send email to the TA saying “I completed Practice Assignment 3” and you’ll get credit. Its totally honor system. If you do something cooler than just run my program (like writing an interesting shader), feel free to attach a picture to the email.

This assignment is due on November 24th. Please do it before you take off for Thanksgiving.

Note: that while getting my program to run (to make sure that textures and shaders work on the computers you will want to use for the upcoming project) is the minimum to do for this assignment, we strongly encourage you to use this as an opportunity to practice writing shaders and using textures. Project 3 is coming, and you’ll need to use shaders and textures for that.

Advice on what to do

For the final project, you will probably want to use the TextureManager and ShaderManager. So, you should look at the example program (and the header files for those tools) to figure out how to use them. You don’t necessarily need to understand how they work internally.

The TextureManager and ShaderManager are admittedly a bit clunky, but they are good enough for the class project. I do not recommend that you put much effort into fixing them. In fact, I wouldn’t even recommend re-writing your own from scratch, since the Project 4 framework code uses them. If you want to put effort in now, focus on learning to write neat shaders.

For this assignment, we don’t care too much what your shader does. A good first thing to try: make a pattern (like a checkerboard) that is properly affected by the light. Try to implement Phong shading.

Note: The ShaderManager is really simple. It prints errors to the console, so make sure you look at the console window if things go wrong.

Note: Shaders may not work unless your computer provides the proper hardware support. The Windows computers in the CSL labs should support shaders.

Some advice on Shaders

You can just write shaders in a text editor and try them out with the sample program.

There are IDEs for writing Shaders. The ones that appear to be “industrial strength” don’t seem to work with GLSL. The ones for GLSL seem to be depricated or abandoned. We used to recommend something called RenderMonkey from AMD (it works OK, even with NVidia hardware), but its been end-of-lifed (but is still available online). If you find one that you think is good, let us know!

Chapter 15 of the OpenGL red book gives a good introduction to GLSL. (if you don’t have a 6th (or later) edition red book, a scan of Chapter 15 is here (only accessable with a UW CS account). We’ll also provide an GLSL reference, Appendix I of the Redbook, here.

You’ll probably want to look at example programs / web tutorials. Here are some that I’ve found (these are old - so if you find others that you think are good, let us know)

Here’s a note on doing anti-aliasing in shaders. Mainly recommended since its yet another example of how to write a shader.http://www.cs.wisc.edu/graphics/Courses/559-f2008/Main/ShaderAntiAliasing

Page last modified on November 17, 2010, at 09:48 AM