Development of the game. Armor. [Log#7]

I would like to draw some analogies that in my opinion fit very clearly.
The class “drawing” I called before RenderDevice, But what is it at all? Why are some classes to fence when there is, for example, Opengl? Of course for ease of use.
Class IRENDERDEVICE can be called an artist, and very well this name is suitable for him.
You can tell the artist “Draw me a square”, in fact, it would be equivalent to such a call in the code “PrenderDevice-> Drawquad (…)”.
The artist cannot draw anything if he does not have canvas, colors and brushes, and here you can again draw an analogy.
The role of the canvas will play the “context of the device” (as I understand it, this is just a special video memory, or rather, part of it) – all windows are available. Everything is clear here The canvas is a window.
Brushes or their equivalent – Models and geometry, it does not even matter 2D or 3D. Perhaps someone knows that geometry (static?) In games on the Source, Idtech and Unrealengine engine, it is called Brush (brush) – probably just a coincidence, I don’t think.
The artist will draw a brush along the canvas, but will not draw anything, so we need paintsTextures, materials, shaders (Shaders). I think many people know what the shader is like – this is a subprogram for a video card, which says how 3D model will be drawn. Screen post-processes \ post-effects are also a shader, for example, a glow (Glow, Bloom), the transition of the picture to grayness / color (this effect was in the game Saboteur).

Analogy describes the set of classes of the graphic library very well, however, it should be noted that there are no specifics. This is a kind of abstraction.
IRENDERDEVICE-artist, and CrenderDeviceogl is some Vasya Pupkin, who is actually also an artist, but as you can already see a specific.

Something like this may look like a class, or rather an interface for the “artist”:

Class IrenderDevice
Public:
// Primary initialization of GAPI devices
Virtual Tressult Init (Windowt *Window, Int Param) = 0;

// initialize the graphic context for a specific application window
Virtual Tressult InitContextForwindow (Windowt *Window) = 0;

// Free the count.Window context
Virtual Tressult CleanupContextForwindow (Windowt *Window) = 0;

// make the current (main) context of the window
Virtual Tressult MakeCurrent (Windowt *Window) = 0;

// change the window of the window image
Virtual Tressult Swapbuffer (Windowt *Window) = 0;

// final cleaning graph.devices
Virtual Tressult Cleanup () = 0;

Virtual Void ApplyView (GView * View) = 0;
Virtual Void SetMaterial (Gmaterial * Material) = 0;
Virtual Void Drawmesh (Gmesh * Mesh) = 0;
>;

The methods of this class have no implementation (specific code) and they are all virtual. It can be seen that the first few methods are initialization, updating the frame and the release of resources (Init, Swapbuffer and Cleanup, respectively) – these functions of the platform -dependent, which is not good at all. But you can slightly get rid of the dependence of “hiding” types and functions dependent on the platform, for example, the type of variable Windowt – arbitrary (determined by me, not a platform), inside which there are platform -dependent variables. This is done in order not to change the call call, for example:
// This code will not need to be changed for each platform
PrenderDevice-> Init (pminwindow, 0);

For each OS, you only have to change / write a code for the Windowt class and some parts from RenderDevice (and \ or other systems).
How the right decision is this – I don’t know for sure, perhaps this is generally a bad solution.

The last three functions of the IRENDERDEVICE interface – “apply the view”, “install the material” and “draw model”. Of course this is not a complete list of functions that will come in handy, but for very simple games I think even that is enough.
Function ApplyView, which takes the pointer to a certain class object GView – A special thing that I can say is proud (although in fact there is nothing). GView is a kind of virtual camera, the boundaries of the species (Vy port \ viewport) and projection matrix. It stores two matrices – projections (promising \ orthogonal) and type (position and direction of the camera).

Classes of material and mesh (Mesh) can generally be usdt casinos any, or rather, the information that is stored in them can be different and depend on the “senior” graphic library (Opengl \ DirectX).

But not only the material and the 3D model depends on the choice of the library, in fact, the entire implementation of the interface depends on it. For example, if you take Opengl, it can be something like this:

Class GrenderDevice: Public IrenderDevice
Public:
GrenderDevice ();
~ GranderDevice ();

// Primary initialization of GAPI devices
Tressult Init (Windowt *Window, Int Param);
// initialize the graphic context for a specific application window
Tressult InitContextForwindow (Windowt *Window);
// Free the count.Window context
Tressult CleanupContextForwindow (Windowt *Window);
// make the current (main) context of the window
Tressult MakeCurrent (Windowt *Window);
// change the window of the window image
Tressult Swapbuffer (Windowt *Window);
// final cleaning graph.devices
Tressult Cleanup ();

VOID ApplyView (GView * View);
VOID DRAWMESH (GMESH * MESH);

VOID DRAWVTEXT (Float X, Float Y, Consta Char *Strtext, Float Size, Bool Breversy = False);

// Flags = 1 – Color, 2 – Depth, 4 – STENCIL
enum bit_color = 0x1,
Bit_depth = 0x2,
Bit_stencl = 0x4
>;
VOID Clearscreen (int flags = 0);
Void Clearscreencolor (Const Float R, Const Float G, Const Float B, const Float A);

VOID BINDTEXTure (Gtexture * Texture);
VOID setWorldMatrix (COST FLOAT * MATRIX);
VOID setwireframe (bool show = true);

Void Drawrect (Float X, Float Y, Float XX, Float Yy);

Protected:
Tressult IniteXTensions ();
Hglrc m_hcontext; // Actually dependent on the platform variable
Windowt *m_powerwindow;
>;

It can be seen that there are more functions, and variables have appeared. (Do not forget that these are examples, but in a real project it will be different). You can create a copy of this class and use all these functions, however, if you need independence from Opengl \ DirectX, then IRENDERDEVICE must be used which has fewer functions. Why then use this cut class? The fact is that the implementation of the artist can be loaded from DLL (if this is realized, of course), for example, this is done in Quake2 – Render and mechanics of the game are loaded from DLL.

Well, let’s say the same ApplyView function for Opengl will look something like this:

Void GrenderDevice :: ApplyView (GView * View)
if ( !View) Return;
// Set a clock
View-> SetViewport (0, 0, Getbufferwidth (), Getbufferheight ());

GlViewport (View-> Getx (), View-> Gety (), View-> Getwidth (), View-> Getheight ());

// Unsan Matrices (Opengl Special Functions)
Glmatrixmode (GL_PROJECTION);
GLLOADMATRIXD (& view-> getprojectionMatrix ().x [0] [0]);
Glmatrixmode (GL_MODELVIEW);
GLLOADMATRIXD (& (View-> GetViewMatrix ()).x [0] [0]);
>

Or here is the function of drawing the grid:
Void GrenderDevice :: DrawMesh (Gmesh * Mesh)
if ( !Mesh) Return;

GverTEX3D * V = MESH-> GETVERTEXARAY ();
Unsigned int Cure = Mesh-> Getcountvertex ();

// Genital functions again
Glvertexpointer (3, GL_FLOAT, SIZEOF (Gvertex3D), & (V [0].x));
Glnormalpointer (GL_FLOAT, SIZEOF (Gvertex3D), & (V [0].NX));
GltexCoordpointer (2, GL_FLOAT, SIZEOF (Gververtex3D), & (V [0].tu));

// Get the number of sub-segment
Unsigned Intsh = Mesh-> GetcountBatches ();

// for each under-net ..
for (Unsigned int i = 0; I < count_batch; ++i )
Gbatch *b = 0;
if (b = mesh-> getbatch (i))

if (b-> m_Materialid != -1)
// Install the texture
Bindtexture (FindTexturebyid (b-> m_Materialid));
>

// Draw triangles
GLDRAWELEMENTS (GL_TRIANGles, B-> GETCOUNT (), GL_UNSIGNED_INT, B-> GETPTR ());
>
>
>

There would be completely different functions for DirectX implementation, but it would not change.
Therefore, calling PrenderDevice-> ApplyView (PView) a specific code will work.

Honestly, it is not very good to explain the whole meaning, but what is there – it’s not at all clear what I wrote here: D

Of course I would like more specific code, but not a teacher 🙁
Moreover, the version of OpenGL, which I previously used, will now have to renew my knowledge a little and pull up the version at least Opengl 3.3.

What’s next ?
I think either to slightly increase the gap between the logs, or take a small pause. I think to start to specifically design the application itself (not to write code) and make a small alpha prototype on some Unity (I really wanted to Gamemaker, but it looks like a new update they refused WinXPSteam refuses to launch GM).