Course list http://www.c-jump.com/bcc/
Now is the time to look at our geometry, add colors, and examine the way we draw things on the screen.
Things to consider:
Here is the source code of the vertex and fragment shaders we are using in this lab:
|
|
Consider the setup of these two shaders:
vPosition and vColor are input varaibles in the vertex shader.
gl_Position is the global variable that the vertex shader must set.
The vertex shader also sets the output variable passColor, which becomes the input variable to the fragment shader.
Once again, the fragment shader passes the color to the output variable fColor
OpenGL draws pixels interpolated between coordinates set in gl_Position with colors specified in fColor.
For the above plan to work, we need to find a way to feed the vertex shader two sets of data:
(a) vertex coordinates that fill each vPosition
(b) vertex colors that fill the vColor
Download c262_lab03.zip and unzip the file under the labs directory. You should get the directory structure
C:\bcc\GL262Labs\labs\c262_lab03
Go ahead and open Visual Studio project
C:\bcc\GL262Labs\labs\c262_lab03\c262_lab03.sln
Compile it:
Build -> Build Solution
(or simply press F7.)
Notice there are two subdirectories,
C:\bcc\GL262Labs\labs\c262_lab03\Shaders C:\bcc\GL262Labs\labs\c262_lab03\src
one for the shaders and another for C++ source code.
The structure of our C++ program is
|
The idea of this lab is to add the Model C++ class to our application. This will allow us to draw multiple models (sky, terrain, and other objects) easily.
The Model class has already been added to the project for you. Take a look at Model.h and Model.cpp.
Look at the constructor of the Model class, understand the purpose of each data member intialized there.
Find implementation of Model::upload_2_server() function in Model.cpp file. Follow the instructions provided there and write code in places indicated by /*YOUR ANSWER*/ comments.
Compile and run the project. If everything's okay, you should see this:
Find implementation of Model::upload_2_server() function in Model.cpp file and add this line at the beginning of the function:
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
Compile and run the program. What do you see now?
Go to your main() function and replace vertices[] and colors[] with
GLfloat vertices[] = {-0.5f, -0.5f, 0.0f, 0.0f, -0.5f, 0.0f, -0.25f, 0.0f, 0.0f, -0.25f, 0.0f, 0.0f, 0.25f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.25f, 0.0f, 0.0f }; GLfloat colors[] = {1.0f, 0.75f, 0.0f, 1.0f, 1.0f, 0.63f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.75f, 0.0f, 1.0f, 1.0f, 0.63f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.75f, 0.0f, 1.0f, 1.0f, 0.63f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f };
Compile and test your program again.
There are no files to submit.
Demonstrate a working c262_lab03 program to your instructor.