Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
render2d.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19 /***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/render2d.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 12/17/01 11:47a $*
30 * *
31 * $Revision:: 26 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42#ifndef RENDER2D_H
43#define RENDER2D_H
44
45#include "always.h"
46//#include "simplevec.h"
47#include "vector.h"
48#include "vector2.h"
49
50#include "shader.h"
51#include "widestring.h"
52#include "rect.h"
53#include "bittype.h"
54
56class TextureClass;
57class Vector3;
58class Vector4;
59
60/*
61** Macros
62*/
63
64//
65// Vector RGB to INT32 methods (normalized components)
66//
67#define VRGB_TO_INT32(rgb) (unsigned(rgb[0]*255.0f)<<16)|(unsigned(rgb[1]*255.0f)<<8)|(unsigned(rgb[2]*255.0f))|0xFF000000
68#define VRGBA_TO_INT32(rgb) (unsigned(rgb[3]*255.0f)<<24)|(unsigned(rgb[0]*255.0f)<<16)|(unsigned(rgb[1]*255.0f)<<8)|(unsigned(rgb[2]*255.0f))
69
70//
71// RGB to INT32 methods (each component is a value from 0 - 255)
72//
73#define RGB_TO_INT32(r,g,b) (unsigned(r)<<16)|(unsigned(g)<<8)|(unsigned(b))|0xFF000000
74#define RGBA_TO_INT32(r,g,b,a) (unsigned(a)<<24)|(unsigned(r)<<16)|(unsigned(g)<<8)|(unsigned(b))
75
76//
77// Float RGB to INT32 methods (each component is a float between 0.0 and 1.0)
78//
79#define FRGB_TO_INT32(r,g,b) (unsigned(r*255.0f)<<16)|(unsigned(g*255.0f)<<8)|(unsigned(b*255.0f))|0xFF000000
80#define FRGBA_TO_INT32(r,g,b,a) (unsigned(a*255.0f)<<24)|(unsigned(r*255.0f)<<16)|(unsigned(g*255.0f)<<8)|(unsigned(b*255.0f))
81
82//
83// INT32 to Vector RGB methods
84//
85#define INT32_TO_VRGB(color, vrgb) \
86 vrgb[0] = ((color & 0x00FF0000) >> 16) / 256.0F; \
87 vrgb[1] = ((color & 0x0000FF00) >> 8) / 256.0F; \
88 vrgb[2] = ((color & 0x000000FF)) / 256.0F;
89
90#define INT32_TO_VRGBA(color, vrgba) \
91 vrgba[0] = ((color & 0x00FF0000) >> 16) / 256.0F; \
92 vrgba[1] = ((color & 0x0000FF00) >> 8) / 256.0F; \
93 vrgba[2] = ((color & 0x000000FF)) / 256.0F; \
94 vrgba[3] = ((color & 0xFF000000) >> 24) / 256.0F;
95
96
97/*
98** Render2DClass
99*/
100class Render2DClass : public W3DMPO
101{
103public:
105 virtual ~Render2DClass(void);
106
107 virtual void Reset(void);
108 void Render(void);
109
110 void Set_Coordinate_Range( const RectClass & range );
111
112 void Set_Texture(TextureClass* tex);
113 TextureClass * Peek_Texture( void ) { return Texture; }
114 void Set_Texture( const char * filename );
115 void Enable_Additive(bool b);
116 void Enable_Alpha(bool b);
117 void Enable_Grayscale(bool b);
118 void Enable_Texturing(bool b);
119
120 ShaderClass * Get_Shader( void ) { return &Shader; }
121 static ShaderClass Get_Default_Shader( void );
122
123 // Add Quad
124 void Add_Quad( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long color = 0xFFFFFFFF );
125 void Add_Quad_Backfaced( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long color = 0xFFFFFFFF );
126 void Add_Quad( const RectClass & screen, const RectClass & uv, unsigned long color = 0xFFFFFFFF );
127 void Add_Quad( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, unsigned long color = 0xFFFFFFFF );
128 void Add_Quad( const RectClass & screen, unsigned long color = 0xFFFFFFFF );
129
130 void Add_Quad_VGradient( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long top_color, unsigned long bottom_color );
131 void Add_Quad_VGradient( const RectClass & screen, unsigned long top_color, unsigned long bottom_color );
132 void Add_Quad_HGradient( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3, const RectClass & uv, unsigned long left_color, unsigned long right_color );
133 void Add_Quad_HGradient( const RectClass & screen, unsigned long left_color, unsigned long right_color );
134
135 // Add Tri
136 void Add_Tri( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & uv0, const Vector2 & uv1, const Vector2 & uv2, unsigned long color = 0xFFFFFFFF );
137
138 // Primitive support
139 void Add_Line( const Vector2 & a, const Vector2 & b, float width, unsigned long color = 0xFFFFFFFF );
140 void Add_Line( const Vector2 & a, const Vector2 & b, float width, const RectClass & uv, unsigned long color = 0xFFFFFFFF );
141 void Add_Line( const Vector2 & a, const Vector2 & b, float width, unsigned long color , unsigned long color2);
142 void Add_Line( const Vector2 & a, const Vector2 & b, float width, const RectClass & uv, unsigned long color, unsigned long color2);
143 void Add_Outline( const RectClass & rect, float width = 1.0F, unsigned long color = 0xFFFFFFFF );
144 void Add_Outline( const RectClass & rect, float width, const RectClass & uv, unsigned long color = 0xFFFFFFFF );
145 void Add_Rect( const RectClass & rect, float border_width = 1.0F, uint32 border_color = 0xFF000000, uint32 fill_color = 0xFFFFFFFF);
146
147 void Set_Hidden( bool hide ) { IsHidden = hide; }
148
149 // Z-value support (this is usefull for playing tricks with the z-buffer)
150 void Set_Z_Value (float z_value) { ZValue = z_value; }
151
152 // Move all verts
153 void Move( const Vector2 & a );
154
155 // Force all alphas
156 void Force_Alpha( float alpha );
157 void Force_Color( int color );
158
159 // Color access
161
162 // statics to access the Screen Resolution in Pixels
163 static void Set_Screen_Resolution( const RectClass & screen );
164 static const RectClass & Get_Screen_Resolution( void ) { return ScreenResolution; }
165
166protected:
173 unsigned short PreAllocatedIndices[60];
179 unsigned long PreAllocatedColors[60];
182 float ZValue;
183
185
187 void Convert_Vert( Vector2 & vert_out, const Vector2 & vert_in );
188 void Convert_Vert( Vector2 & vert_out, float x_in, float y_in );
189 void Update_Bias( void );
190
191 void Internal_Add_Quad_Vertices( const Vector2 & v0, const Vector2 & v1, const Vector2 & v2, const Vector2 & v3 );
192 void Internal_Add_Quad_Vertices( const RectClass & screen );
193 void Internal_Add_Quad_UVs( const RectClass & uv );
194 void Internal_Add_Quad_Colors( unsigned long color );
195 void Internal_Add_Quad_VColors( unsigned long color1, unsigned long color2 );
196 void Internal_Add_Quad_HColors( unsigned long color1, unsigned long color2 );
197 void Internal_Add_Quad_Indicies( int start_vert_index, bool backfaced = false );
198};
199
200
201/*
202** Render2DTextClass
203*/
205public:
208
209 virtual void Reset(void);
210
211 Font3DInstanceClass * Peek_Font( void ) { return Font; }
212 void Set_Font( Font3DInstanceClass *font );
213
214 void Set_Location( const Vector2 & loc ) { Location = loc; Cursor = loc; }
215 void Set_Wrapping_Width (float width) { WrapWidth = width; }
216
217 // Clipping support
218 void Set_Clipping_Rect( const RectClass &rect ) { ClipRect = rect; IsClippedEnabled = true; }
219 bool Is_Clipping_Enabled( void ) const { return IsClippedEnabled; }
220 void Enable_Clipping( bool onoff ) { IsClippedEnabled = onoff; }
221
222 void Draw_Text( const char * text, unsigned long color = 0xFFFFFFFF );
223 void Draw_Text( const WCHAR * text, unsigned long color = 0xFFFFFFFF );
224
225 void Draw_Block( const RectClass & screen, unsigned long color = 0xFFFFFFFF );
226
227 const RectClass & Get_Draw_Extents( void ) { return DrawExtents; }
228 const RectClass & Get_Total_Extents( void ) { return TotalExtents; }
229 const Vector2 & Get_Cursor( void ) { return Cursor; }
230
231 Vector2 Get_Text_Extents( const WCHAR * text );
232
233private:
235 Vector2 Location;
236 Vector2 Cursor;
237 float WrapWidth;
238 RectClass DrawExtents;
239 RectClass TotalExtents;
240 RectClass BlockUV;
241 RectClass ClipRect;
242 bool IsClippedEnabled;
243
244 void Draw_Char( WCHAR ch, unsigned long color );
245};
246
247#endif // RENDER2D_H
#define NULL
Definition BaseType.h:92
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
unsigned long uint32
Definition bittype.h:46
void Enable_Additive(bool b)
Definition render2d.cpp:164
void Enable_Grayscale(bool b)
added for generals to draw disabled button states - MW
Definition render2d.cpp:146
TextureClass * Texture
Definition render2d.h:170
void Internal_Add_Quad_UVs(const RectClass &uv)
Definition render2d.cpp:317
DynamicVectorClass< unsigned long > & Get_Color_Array(void)
Definition render2d.h:160
void Render(void)
Definition render2d.cpp:604
void Set_Hidden(bool hide)
Definition render2d.h:147
void Add_Rect(const RectClass &rect, float border_width=1.0F, uint32 border_color=0xFF000000, uint32 fill_color=0xFFFFFFFF)
Definition render2d.cpp:563
void Internal_Add_Quad_Colors(unsigned long color)
Definition render2d.cpp:332
void Move(const Vector2 &a)
Definition render2d.cpp:268
Vector2 PreAllocatedUVCoordinates[60]
Definition render2d.h:177
void Add_Quad(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:413
void Set_Coordinate_Range(const RectClass &range)
Definition render2d.cpp:188
void Update_Bias(void)
Definition render2d.cpp:199
static void Set_Screen_Resolution(const RectClass &screen)
Definition render2d.cpp:92
void Add_Outline(const RectClass &rect, float width=1.0F, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:586
Vector2 CoordinateOffset
Definition render2d.h:168
DynamicVectorClass< unsigned short > Indices
Definition render2d.h:172
void Enable_Alpha(bool b)
Definition render2d.cpp:151
void Internal_Add_Quad_Indicies(int start_vert_index, bool backfaced=false)
Definition render2d.cpp:376
void Force_Color(int color)
Definition render2d.cpp:288
Vector2 PreAllocatedVertices[60]
Definition render2d.h:175
void Internal_Add_Quad_Vertices(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3)
Definition render2d.cpp:300
void Add_Quad_Backfaced(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:421
DynamicVectorClass< Vector2 > UVCoordinates
Definition render2d.h:176
void Add_Quad_VGradient(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long top_color, unsigned long bottom_color)
Definition render2d.cpp:429
TextureClass * Peek_Texture(void)
Definition render2d.h:113
Vector2 CoordinateScale
Definition render2d.h:167
unsigned long PreAllocatedColors[60]
Definition render2d.h:179
static const RectClass & Get_Screen_Resolution(void)
Definition render2d.h:164
void Set_Texture(TextureClass *tex)
Definition render2d.cpp:130
DynamicVectorClass< Vector2 > Vertices
Definition render2d.h:174
bool IsGrayScale
Definition render2d.h:181
unsigned short PreAllocatedIndices[60]
Definition render2d.h:173
Vector2 BiasedCoordinateOffset
Definition render2d.h:169
void Add_Line(const Vector2 &a, const Vector2 &b, float width, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:524
ShaderClass * Get_Shader(void)
Definition render2d.h:120
virtual void Reset(void)
Definition render2d.cpp:120
void Add_Quad_HGradient(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &v3, const RectClass &uv, unsigned long left_color, unsigned long right_color)
Definition render2d.cpp:437
void Internal_Add_Quad_VColors(unsigned long color1, unsigned long color2)
Definition render2d.cpp:346
void Add_Tri(const Vector2 &v0, const Vector2 &v1, const Vector2 &v2, const Vector2 &uv0, const Vector2 &uv1, const Vector2 &uv2, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:490
Render2DClass(TextureClass *tex=NULL)
Definition render2d.cpp:70
DynamicVectorClass< unsigned long > Colors
Definition render2d.h:178
void Internal_Add_Quad_HColors(unsigned long color1, unsigned long color2)
Definition render2d.cpp:361
virtual ~Render2DClass(void)
Definition render2d.cpp:87
void Force_Alpha(float alpha)
Definition render2d.cpp:278
void Set_Z_Value(float z_value)
Definition render2d.h:150
ShaderClass Shader
Definition render2d.h:171
static RectClass ScreenResolution
Definition render2d.h:184
void Enable_Texturing(bool b)
Definition render2d.cpp:178
static ShaderClass Get_Default_Shader(void)
Definition render2d.cpp:105
Vector2 Convert_Vert(const Vector2 &v)
void Set_Font(Font3DInstanceClass *font)
Definition render2d.cpp:742
void Set_Location(const Vector2 &loc)
Definition render2d.h:214
bool Is_Clipping_Enabled(void) const
Definition render2d.h:219
const Vector2 & Get_Cursor(void)
Definition render2d.h:229
void Set_Clipping_Rect(const RectClass &rect)
Definition render2d.h:218
void Draw_Block(const RectClass &screen, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:837
const RectClass & Get_Draw_Extents(void)
Definition render2d.h:227
const RectClass & Get_Total_Extents(void)
Definition render2d.h:228
virtual void Reset(void)
Definition render2d.cpp:731
void Set_Wrapping_Width(float width)
Definition render2d.h:215
void Enable_Clipping(bool onoff)
Definition render2d.h:220
Render2DTextClass(Font3DInstanceClass *font=NULL)
Definition render2d.cpp:712
Vector2 Get_Text_Extents(const WCHAR *text)
Definition render2d.cpp:847
Font3DInstanceClass * Peek_Font(void)
Definition render2d.h:211
void Draw_Text(const char *text, unsigned long color=0xFFFFFFFF)
Definition render2d.cpp:792