forked from KapLex/PGE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgeGfx.h
588 lines (504 loc) · 13.9 KB
/
pgeGfx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*
* pgeGfx.h: Header for Graphics
*
* This file is part of "Phoenix Game Engine".
*
* This file is part of "Phoenix Game Engine".
*
* Copyright (C) 2008 Phoenix Game Engine
* Copyright (C) 2008 InsertWittyName <[email protected]>
* Copyright (C) 2008 MK2k <[email protected]>
*
* Phoenix Game Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Phoenix Game Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Phoenix Game Engine. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __PGEGFX_H__
#define __PGEGFX_H__
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup pgeGfx Graphics Library
* @{
*/
#include <pspgu.h>
#include "pgeTexture.h"
#include "pgeObj.h"
#define ARGB(a, r, g, b) ((a << 24) | (r << 16) | (g << 8) | b)
#define RGBA(r, g, b, a) ((a << 24) | (b << 16) | (g << 8) | r)
typedef struct
{
float x, y, z;
} pgeVertV;
typedef struct
{
float nx, ny, nz;
float x, y, z;
} pgeVertNV;
typedef struct
{
unsigned int color;
float x, y, z;
} pgeVertCV;
typedef struct
{
unsigned int color;
float nx, ny, nz;
float x, y, z;
} pgeVertCNV;
typedef struct
{
float u, v;
float x, y, z;
} pgeVertTV;
typedef struct
{
float u, v;
float nx, ny, nz;
float x, y, z;
} pgeVertTNV;
typedef struct
{
float u, v;
unsigned int color;
float x, y, z;
} pgeVertTCV;
typedef struct
{
float u, v;
unsigned int color;
float nx, ny, nz;
float x, y, z;
} pgeVertTCNV;
typedef struct
{
float x, y, w, h;
} pgeRect;
typedef struct
{
ScePspFVector3 eye;
ScePspFVector3 center;
ScePspFVector3 up;
} pgeCamera;
/**
* Enum for vertex types.
*/
enum pgeGfxVertexType
{
PGE_VERT_V = GU_VERTEX_32BITF,
PGE_VERT_NV = GU_NORMAL_32BITF|GU_VERTEX_32BITF,
PGE_VERT_CV = GU_COLOR_8888|GU_VERTEX_32BITF,
PGE_VERT_CNV = GU_COLOR_8888|GU_NORMAL_32BITF|GU_VERTEX_32BITF,
PGE_VERT_TV = GU_TEXTURE_32BITF|GU_VERTEX_32BITF,
PGE_VERT_TNV = GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF,
PGE_VERT_TCV = GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF,
PGE_VERT_TCNV = GU_TEXTURE_32BITF|GU_COLOR_8888|GU_NORMAL_32BITF|GU_VERTEX_32BITF
};
/**
* Enum for primitive types.
*/
enum pgeGfxPrim
{
PGE_PRIM_POINTS,
PGE_PRIM_LINES,
PGE_PRIM_LINE_STRIP,
PGE_PRIM_TRIANGLES,
PGE_PRIM_TRIANGLE_STRIP,
PGE_PRIM_TRIANGLE_FAN,
PGE_PRIM_SPRITES
};
/**
* Enum for blend modes.
*/
enum pgeBlendMode
{
PGE_BLEND_MODE_TRANSPARENT,
PGE_BLEND_MODE_REGULAR
};
/**
* Enum for vertical sync.
*/
enum pgeWaitVsync
{
PGE_NO_WAIT_VSYNC = 0, /**< Don't wait for vblank. */
PGE_WAIT_VSYNC /**< Wait for vblank. */
};
#define PGE_GFX_PROJECTION GU_PROJECTION
#define PGE_GFX_VIEW GU_VIEW
#define PGE_GFX_MODEL GU_MODEL
/**
* Get current framebuffer
*
* @returns A pointer to the current framebuffer.
*/
unsigned int *pgeGfxGetFramebuffer(void);
/**
* Init graphics.
*
* @param pixelformat - One of ::pgePixelFormat
*
* @returns 1 on success, 0 on error.
*/
int pgeGfxInit(enum pgePixelFormat pixelformat);
/**
* Shutdown graphics.
*/
void pgeGfxShutdown(void);
/**
* Start drawing.
*/
void pgeGfxStartDrawing(void);
/**
* End drawing.
*/
void pgeGfxEndDrawing(void);
/**
* Swap the framebuffers.
*
* @param vsync - One of ::pgeWaitVsync
*/
void pgeGfxSwapBuffers(enum pgeWaitVsync vsync);
/**
* Clear the screen.
*
* @param color - The color to clear the screen to.
*/
void pgeGfxClearScreen(unsigned int color);
/**
* Create a 32-bit color.
*
* @param r - The red value (0-255).
*
* @param g - The green value (0-255).
*
* @param b - The blue value (0-255).
*
* @param a - The alpha value (0-255).
*
* @returns The color in 0xAABBGGRR format.
*/
unsigned int pgeGfxCreateColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
/**
* Render to a texture.
*
* @param texture - The texture to render to (must reside in VRAM).
*/
void pgeGfxRenderToTexture(pgeTexture *texture);
/**
* Render to screen.
*
* @param color - The color to clear the screen to.
*/
void pgeGfxRenderToScreen(void);
/**
* Set the blend mode.
*
* @param mode - One of ::pgeBlendMode.
*
* @returns The previous blend mode.
*/
int pgeGfxSetBlendMode(enum pgeBlendMode mode);
/**
* Set 3D camera drawing mode.
*
* @param fov - The field of view to set.
*
* @param cam - Pointer to a ::pgeCamera.
*/
void pgeGfxSetMode3DCamera(float fov, pgeCamera *cam);
/**
* Draw a line.
*
* @param startx - The start x position of the line.
*
* @param starty - The start y position of the line.
*
* @param endx - The end x position of the line.
*
* @param endy - The end y position of the line.
*
* @param color - The color of the line.
*/
void pgeGfxDrawLine(float startx, float starty, float endx, float endy, unsigned int color);
/**
* Draw a star.
*
* @param x - The central position of the star on the x axis.
*
* @param y - The central position of the star on the y axis.
*
* @param outerradius - The outer radius of the star.
*
* @param innerradius - The inner radius of the star.
*
* @param numpoints - Number of points of the star.
*
* @param color - The color of the star.
*
* @param angle - The rotation of the star.
*/
void pgeGfxDrawStar(float x, float y, float outerradius, float innerradius, unsigned int numpoints, unsigned int color, float angle);
/**
* Draw an outline star.
*
* @param x - The central position of the star on the x axis.
*
* @param y - The central position of the star on the y axis.
*
* @param outerradius - The outer radius of the star.
*
* @param innerradius - The inner radius of the star.
*
* @param numpoints - Number of points of the star.
*
* @param color - The color of the star.
*
* @param angle - The rotation of the star.
*/
void pgeGfxDrawStarOutline(float x, float y, float outerradius, float innerradius, unsigned int numpoints, unsigned int color, float angle);
/**
* Draw a circle.
*
* @param x - The central position of the circle on the x axis.
*
* @param y - The central position of the circle on the y axis.
*
* @param radius - The radius of the circle.
*
* @param numsteps - Number of steps to take when generating the circle (higher is better quality).
*
* @param color - The color of the circle.
*/
void pgeGfxDrawCircle(float x, float y, float radius, unsigned int numsteps, unsigned int color);
/**
* Draw an outline circle.
*
* @param x - The central position of the circle on the x axis.
*
* @param y - The central position of the circle on the y axis.
*
* @param radius - The radius of the circle.
*
* @param numsteps - Number of steps to take when generating the circle (higher is better quality).
*
* @param color - The color of the circle.
*/
void pgeGfxDrawCircleOutline(float x, float y, float radius, unsigned int numsteps, unsigned int color);
/**
* Draw a rectangle.
*
* @param destrect - A ::pgeRect that contains the x, y, width & height.
*
* @param color - The color of the rectangle.
*
* @param angle - The rotation of the rectangle.
*/
void pgeGfxDrawRect(pgeRect *destrect, unsigned int color, float angle);
/**
* Draw an outline rectangle.
*
* @param destrect - A ::pgeRect that contains the x, y, width & height.
*
* @param color - The color of the rectangle.
*
* @param angle - The rotation of the rectangle.
*/
void pgeGfxDrawRectOutline(pgeRect *destrect, unsigned int color, float angle);
/**
* Draw a gradient rectangle.
*
* @param destrect - A ::pgeRect that contains the x, y, width & height.
*
* @param color1 - The color of the rectangle's XXX XXX point.
*
* @param color2 - The color of the rectangle's XXX XXX point.
*
* @param color3 - The color of the rectangle's XXX XXX point.
*
* @param color4 - The color of the rectangle's XXX XXX point.
*
* @param angle - The rotation of the rectangle.
*/
void pgeGfxDrawRectGrad(pgeRect *destrect, unsigned int color1, unsigned int color2, unsigned int color3, unsigned int color4, float angle);
/**
* Draw a texture (easy).
*
* @param texture - A ::pgeTexture.
*
* @param x - The x position of the texture.
*
* @param y - The y position of the texture.
*
* @param angle - The rotation of the texture.
*
* @param alpha - The transparency of the texture (0-255).
*/
void pgeGfxDrawTextureEasy(pgeTexture *texture, float x, float y, float angle, unsigned char alpha);
/**
* Draw a texture.
*
* @param destrect - A ::pgeRect that contains the x, y, width & height.
*
* @param sourcerect - A ::pgeRect that contains the u, v, width & height.
*
* @param angle - The rotation of the texture.
*
* @param alpha - The transparency of the texture (0-255).
*/
void pgeGfxDrawTexture(pgeRect *destrect, pgeRect *sourcerect, float angle, unsigned char alpha);
/**
* Draw a texture in a given color.
*
* @param destrect - A ::pgeRect that contains the x, y, width & height.
*
* @param sourcerect - A ::pgeRect that contains the u, v, width & height.
*
* @param angle - The rotation of the texture.
*
* @param color - A ::pgeColorRGB specifying the color in which the texture should be drawn
*/
void pgeGfxDrawTextureColored(pgeRect *destrect, pgeRect *sourcerect, float angle, unsigned int color);
/**
* Get display list memory.
*
* @param size - Display list size required (in bytes).
*
* @returns A pointer to the memory.
*/
void *pgeGfxGetVertexMemory(int size);
/**
* Draw custom (2D).
*
* @param prim - One of ::pgeGfxPrim.
*
* @param vtype - One of ::pgeGfxVertexType.
*
* @param count - Number of vertices.
*
* @param vertices - A pointer to the vertex data.
*/
void pgeGfxDrawCustom2D(enum pgeGfxPrim prim, enum pgeGfxVertexType vtype, int count, const void *vertices);
/**
* Draw custom (3D).
*
* @param position - Vector holding the position.
*
* @param rotation - Vector holding the rotation.
*
* @param prim - One of ::pgeGfxPrim.
*
* @param vtype - One of ::pgeGfxVertexType.
*
* @param count - Number of vertices.
*
* @param vertices - A pointer to the vertex data.
*/
void pgeGfxDrawCustom3D(ScePspFVector3 *position, ScePspFVector3 *rotation, enum pgeGfxPrim prim, enum pgeGfxVertexType vtype, int count, const void *vertices);
/**
* Draw texture (3D).
*
* @param position - Vector holding the position.
*
* @param rotation - Vector holding the rotation.
*
* @param width - Width to be drawn.
*
* @param height - Height to be drawn.
*/
void pgeGfxDrawTexture3D(ScePspFVector3 *position, ScePspFVector3 *rotation, float width, float height);
/**
* Draw texture (3D) in a given color.
*
* @param position - Vector holding the position.
*
* @param rotation - Vector holding the rotation.
*
* @param width - Width to be drawn.
*
* @param height - Height to be drawn.
*
* @param color - pgeColorRGB containing the color and alpha the texture has to be drawn in.
*/
void pgeGfxDrawTexture3DColored(ScePspFVector3 *position, ScePspFVector3 *rotation, float width, float height, unsigned int color);
/**
* Draw a cube.
*
* @param position - Vector holding the position.
*
* @param rotation - Vector holding the rotation.
*
* @param width - The width of the cube.
*
* @param height - The height of the cube.
*
* @param depth - The depth of the cube.
*
* @param color - The color of the cube.
*/
void pgeGfxDrawCube(ScePspFVector3 *position, ScePspFVector3 *rotation, float width, float height, float depth, unsigned int color);
/**
* Draw a textured cube.
*
* @param position - Vector holding the position.
*
* @param rotation - Vector holding the rotation.
*
* @param width - The width of the cube.
*
* @param height - The height of the cube.
*
* @param depth - The depth of the cube.
*/
void pgeGfxDrawCubeTexture(ScePspFVector3 *position, ScePspFVector3 *rotation, float width, float height, float depth);
/**
* Draw an OBJ file.
*
* @param obj - Pointer to a ::pgeObj.
*
* @param position - Vector holding the position.
*
* @param rotation - Vector holding the rotation.
*/
void pgeGfxDrawObj(pgeObj *obj, ScePspFVector3 *position, ScePspFVector3 *rotation);
void pgeGfxDrawTextureColored(pgeRect *destrect, pgeRect *sourcerect, float angle, unsigned int color);
int pgeGfxGetMatrix(ScePspFMatrix4 *m, int mode);
void pgeGfxRotateY(float angle);
void pgeGfxRotateX(float angle);
void pgeGfxLookAt(ScePspFVector3* eye, ScePspFVector3* center, ScePspFVector3* up);
void pgeGfxPerspective(float fovy, float aspect, float near, float far);
void pgeGfxMatrixMode(int mode);
void pgeGfxLoadIdentity(void);
int pgeGfxProject(ScePspFVector3 *object, ScePspFVector3 *screen);
int pgeGfxUnproject(ScePspFVector3 *screen, ScePspFVector3 *object);
void pgeGfxSetTransparent(unsigned int color);
void pgeGfxUnsetTransparent(void);
unsigned int pgeGfxColorSub(unsigned int color1, unsigned int color2);
unsigned int pgeGfxColorAdd(unsigned int color1, unsigned int color2);
unsigned int pgeGfxColorMul(unsigned int color1, unsigned int color2);
unsigned int pgeGfxColorMulScalar(unsigned int color, float scalar);
unsigned int pgeGfxColorDivScalar(unsigned int color, float scalar);
int pgeGfxColorCompare(unsigned int color1, unsigned int color2);
unsigned int pgeGfxColorClamp(unsigned int color);
#ifdef INCLUDE_HSV
//pgeColorHSV pgeGfxColorHSVSub(pgeColorHSV col1, pgeColorHSV col2);
//pgeColorHSV pgeGfxColorHSVAdd(pgeColorHSV col1, pgeColorHSV col2);
//pgeColorHSV pgeGfxColorHSVMul(pgeColorHSV col1, pgeColorHSV col2);
//pgeColorHSV pgeGfxColorHSVDiv(pgeColorHSV color, float scalar);
//int pgeGfxColorHSVCompare(pgeColorHSV col1, pgeColorHSV col2);
//pgeColorHSV pgeGfxColorHSVClamp(pgeColorHSV color);
//void pgeGfxColorHSVSetHWColor(pgeColorHSV *color, u32 hwcol);
//u32 pgeGfxColorHSVGetHWColor(pgeColorHSV color);
#endif
/** @} */
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __PGEGFX_H__