--Chapter 4: Another Mode of Rendering—
When it comes to creating vertices you don’t always have to create an array to define them. The type of homebrew this is called is ‘immediate mode’ and it means to immediately create vertices in the scene render function. You also do not need a VBO, buffers, or a vertex list count to create Citro3D homebrew in this mode.
NOTE: Citra doesn’t support immediate mode, due to the hardware requirements, so you can only test this homebrew on actual hardware.
We’re going to take to code from Chapter 2 and edit it into immediate mode.
First thing is to remove the unnecessary parts of code. First, go to the top of the file to the vertex array and remove that array. Then, delete the “vbo_data” variable. Next, delete the vertex_list_count variable defined. Then go down and delete the “vbo_data” function and the “memcpy” function. Go down in the same function and delete the functions in the buffer area (‘C3D_GetBufInfo”, “BufInfo_Init”, “BufInfo_Add”). Next, go to the “C3D_DrawArrays” function in the scene render function and remove that one since we’ll be replacing it with an immediate mode function. Lastly, go to the scene function and remove the “linearFree” function since they aren’t needed.
Now, the first function to edit is the “AttrInfo_AddFixed” function. Change it to “AttrInfo_AddLoader” function and add the arguments “GPU_FLOAT” and 3. The attribute format and element however are ignored in immediate mode, so just keep the last 2 arguments valid but it doesn’t matter what you put there.
The next and last thing you will do is go to the scene render function and add the function “C3D_ImmDrawBegin”. It has one argument which is the primitive and since this is basic homebrew, you’ll use “GPU_TRIANGLES” as the argument. Now you will create 3 sets of 2 function which is all the same function (C3D_ImmSendAttrib). The first one in a set will be the position and the second one in the set will be the color.
The only way it knows which one is which is that the last value is either 0 or 1 (v0 being position and v*1 being color).
*I actually don’t know but this is the closest I could get. The other description would have been that since there’s only 2 registers stored, then it goes back and forwards. This description may actually be more possible then the one I said.
The functions have 4 arguments which are X, Y, Z, and W (RBGA in color). The functions should look like:
C3D_ImmSendAttrib(200.0f, 200.0f, 0.5f, 0.0f); // v0=position
C3D_ImmSendAttrib(1.0f, 0.0f, 0.0f, 1.0f); // v1=color
C3D_ImmSendAttrib(100.0f, 40.0f, 0.5f, 0.0f);
C3D_ImmSendAttrib(0.0f, 1.0f, 0.0f, 1.0f);
C3D_ImmSendAttrib(300.0f, 40.0f, 0.5f, 0.0f);
C3D_ImmSendAttrib(0.0f, 0.0f, 1.0f, 1.0f);
Immediately followed by the function “C3D_ImmDrawEnd”. It has no arguments so just put parentheses and a semicolon and you’re done.
And that’s all there is to immediate mode. In the next chapter, we’ll learn more about color and coloring your vertices.