For more realistic image we'll need light and shades, which will require new shaders. We will use Phong shading model. Let's start with a uniform color shader. 1. Vertex shader. Copy following code in a Text Editor and save is as a txt file in C:\CPP\engine\dt\shaders\phong_ucolor_v.txt 2. Fragment shader. Copy following code in a Text […]
Category: Cross-platform 3D
Chapter 18. Camera view
In our previous chapters we used straight projection of our subject to the "screen surface". For more realistic picture we need Camera. OpenGL ES doesn't offer an embedded camera object, so we'll need to create one. Windows 1. Start VS. Open C:\CPP\a997modeler\p_windows\p_windows.sln. To see the difference with Camera view let's first simplify our box movement. 2. […]
Chapter 17. Modeler. Part 2
Now back to the modeler. Time to put all these new classes together. Windows 1. Start VS. Open C:\CPP\a997modeler\p_windows\p_windows.sln. 2. Under modeler add new header file ModelBuilder.h Location - C:\CPP\engine\modeler Code: In this sample we will create a red box with 1 blue side (the right one). For this we will need to create 1 GameSubject, […]
Chapter 16. Modeler
Now it's time to think where to get actual 3D models for our Project. Our options are: So, let's start with the last option - generate models programmatically. It will be a set of tools and classes, a considerable part of our engine. Let's create a placeholder for it. 1. In Windows File Explorer under […]
Chapter 15. Indexes and EBO - Element Buffer Object
In our latest samples we used GL_TRIANGLE_STRIP primitive (to draw a rectangle as a sequential array of vertices). But the most useful and most common primitive is GL_TRIANGLES. We used it earlier to draw a triangle (assuming that vertices go in correct sequential order). For more complicated surfaces normal approach is to keep an array […]
Chapter 14. 3D Coordinates and Game Subjects
3D subject will require 3D coordinates including orientation angles. We will need Euler angles (yaw, pitch, and roll in aviation terminology or heading, attitude and bank in naval). We'll start with Euler angles in degrees and in radians and a rotation Matrix. We'll call this class Coords. Windows 1. Start VS. Open C:\CPP\a998engine\p_windows\p_windows.sln. 2. Under […]
Chapter 13. Basic classes 2
Windows 1. Start VS. Open C:\CPP\a998engine\p_windows\p_windows.sln MyColor class The reason to have it as a separate class, is that we will need to keep colors in THREE different formats: as an array of 4 single byte integers (from 0 to 255, as it is stored in files) as an array of 4 floats (from 0.0 to […]
Chapter 12. Graphics Engine. Basic classes
At this point we successfully married desktop and mobile, Visual Studio and OpenGL ES. Now we are starting to implement our graphics engine. Sure, it can be done in many different ways. Warning: All following materials represent my personal vision of this topic. We'll start from basic classes. Our current TheGame code renders 1 simple […]
Chapter 11. Textures
1. To use textures, we first need to load them into the application. Using an image-loading library that supports several popular formats looks like a good solution. I like stb_image.h by Sean Barrett. Especially I love that it's a single h-file, not a lib or dll. You can download it here. Save it in C:\CPP\engine […]
Chapter 10. Simple shader
Finally, shaders! Let's start from the easiest one, just flat uniform color, which we will pass to the shader as an input, along with mesh data (in our sample - a triangle). Shaders use GLSL (OpenGL Shading Language with syntax similar to C). GLSL is executed directly by the graphics pipeline. The executable shader program […]