Tutorial: Rendering ROSE Items in OpenGL and C++ (Part 1)
The aim of this tutorial is to render ROSE items up to the point of showing a full player with items! How exciting. It will be based upon the use of OpenGL and C++ using the Windows API to setup the window. This tutorial is not really aimed at those who cannot do C++ but more at those who are competent need help with 3D and OpenGL. I may also stress that this ‘tutorial’ as such is not going to tell you in depth how to create the code yourself but be a light informative source on how the code works, you will have to download the source for yourself to get the full idea.
The first boring bit is creating the window and all that rubbish, so I have decided to go ahead and do that for you and create a very basic framework from which we will work off of. This framework includes creating the OpenGL window, a few math classes such as support for Matrices and Vectors and a Camera class. This leaves me to focus the tutorial on uses OpenGL to render the items as the code mentioned beforehand is not really anything new or special to ROSE and can be found anywhere.
So if you download my basic framework and compile it you will see that there is just 3 axis lines which you can move the camera around using the right mouse button with dragging to rotate and the mouse wheel to zoom in and out. This is not very pretty at all! So we shall now focus on loading ZMS, the ROSE mesh files, into this application.
The file format for ZMS can be found here: ZMS File Format
It is pretty simple to load this into memory, the only trick is using the bone lookups. At the beginning of the file there is a list of bone indices, these are the actual bone index of the ZMD, the ROSE skeleton files, I name it the ‘bone lookup’ list. The BoneWeights for each vertex actually reference an ID in the bone lookup list. Here is an example: the first bone for a vertex would actually be boneLookup[boneWeight.id[0]] for the correct index in the ZMD file.
There are multiple ways to render this model, I use things called Vertex Buffer Objects which actually upload the model data into your graphics card and uses the RAM on it to store the data there. This is much faster as the vertex data does not get sent every frame. Unfortunately to use VBOs we must use OpenGL ARB extensions which makes our code a lot messier
. The required functions are: glBindBuffer, glGenBuffers, glBufferData and glDeleteBuffers for clean up.
To load these extensions we have to call the function wglGetProcAddress (when on Windows), and example for glGenBuffers:
PFNGLGENBUFFERSPROC glGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffers");
The type PFNGLGENBUFFERSPROC is defined in gl/glext.h which is an include which should come with the OpenGL headers which can be found in the windows sdk.
There are two types of buffers I use, Vertex Buffers and Index Buffers, the difference is Vertex Buffers store the per-vertex data such as position, UV coordinates, colouring, normals etc whereas Index Buffers store the face -> vertex links. ROSE ZMS files are defined with a list of vertices and a list of faces which reference those vertices. These faces -> vertex references are loaded into and index buffer and used to draw faces from the list of vertices.
I also created two helper functions for creating Vertex Buffers and Index Buffers:
GLuint CreateIndexBuffer(void* data, unsigned int size){
GLuint buf = 0;
glGenBuffers(1, &buf);
if(!buf) return -1;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
return buf;
}
GLuint CreateVertexBuffer(void* data, unsigned int size){
GLuint buf;
glGenBuffers(1, &buf);
if(!buf) return -1;
glBindBuffer(GL_ARRAY_BUFFER, buf);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
return buf;
}
As you can see these take two arguments, data and size. The data should be an array of the vertex data, this is not only vertex positions but also uv maps, normals, colours or any other per vertex data you would like to send to the graphics card, to render from these buffers you can use the glVertexPointer and glDrawElements calls.
As mesh rendering now works at this point (I am writing the code as I write the tutorial) I come to the problem of texture loading, this requires an external library as we are loading DDS files which are not natively compliant with OpenGL! I use the DevIL library which I have always found to be reliable and work with the ROSE textures.
With an addition of loading images from DevIL and using glTexCoordPointer we can now render the textured ZMS:
As the first part of this ‘tutorial’ comes to an end I realise this is either 1. a really shit tutorial or 2. not really a tutorial at all. There is the bare minimum of explanation here, it is more of a source code release with a slight explanation. I apologise for this, but maybe once this rendering engine is complete I can make a nice item viewer and people will use that rather than read this ‘tutorial’
.
Coming up in the part 2: using the ZSC files to render full models!
Edit: Sorry I forgot the source, you can find it here: Rendering ROSE Part 1

Just make a wrapper for ZnZin.dll! The one that xadet made works wonders for item rendering!
where is the source? or are you gonna post it in part 2?
@rl-1 Just use arcturus instead of osrose? No reason why we cannot use our own rendering engine. Who knows, I might have something special planned for it
.
@csharp Source is not included, look at the end of this ‘tutorial’ xD
Ooohhh, now I am excited. I am not saying that you should use ZnZin.dll, it’s just easier for item rendering! Overall, if we use our own rendering engine we can do a lot more! AKA Item manipulation and eventually creation!
exjam are you going to fix the rose3D Engine and jrose patch stealer?