1 /************************************************************************************
2
3 AstroMenace
4 Hardcore 3D space scroll-shooter with spaceship upgrade possibilities.
5 Copyright (c) 2006-2019 Mikhail Kurinnoi, Viewizard
6
7
8 AstroMenace is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 AstroMenace is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with AstroMenace. If not, see <https://www.gnu.org/licenses/>.
20
21
22 Website: https://viewizard.com/
23 Project: https://github.com/viewizard/astromenace
24 E-mail: viewizard@viewizard.com
25
26 *************************************************************************************/
27
28 // NOTE the matrix stack and related matrix manipulation functions deprecated in OpenGL 3.1 core profile
29 // https://www.khronos.org/registry/OpenGL/specs/gl/glspec30.pdf
30 // E.1. PROFILES AND DEPRECATED FEATURES OF OPENGL 3.0
31
32 /*
33 We don't check pointers status, since we don't work with pointers
34 but only provide them to OpenGL functions, let OpenGL check them.
35 */
36
37 #include "../math/math.h"
38 #include "graphics.h"
39
40 namespace viewizard {
41
42 /*
43 * Replace the current matrix with the identity matrix.
44 */
vw_LoadIdentity()45 void vw_LoadIdentity()
46 {
47 glLoadIdentity();
48 }
49
50 /*
51 * Produce a translation by sVECTOR3D.
52 */
vw_Translate(sVECTOR3D Location)53 void vw_Translate(sVECTOR3D Location)
54 {
55 glTranslatef(Location.x, Location.y, Location.z);
56 }
57
58 /*
59 * Produce a rotation of angle degrees around the vector x, y and z.
60 */
vw_Rotate(GLfloat angle,GLfloat x,GLfloat y,GLfloat z)61 void vw_Rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
62 {
63 glRotatef(angle, x, y, z);
64 }
65
66 /*
67 * Produce a nonuniform scaling along the x, y, and z axes.
68 */
vw_Scale(GLfloat x,GLfloat y,GLfloat z)69 void vw_Scale(GLfloat x, GLfloat y, GLfloat z)
70 {
71 glScalef(x, y, z);
72 }
73
74 /*
75 * Get matrix from the top of the matrix stack.
76 */
vw_GetMatrix(eMatrixPname pname,GLfloat * params)77 void vw_GetMatrix(eMatrixPname pname, GLfloat *params)
78 {
79 glGetFloatv(static_cast<GLenum>(pname), params);
80 }
81
82 /*
83 * Replace the current matrix with an arbitrary matrix.
84 */
vw_SetMatrix(const GLfloat * matrix)85 void vw_SetMatrix(const GLfloat *matrix)
86 {
87 glLoadMatrixf(matrix);
88 }
89
90 /*
91 * Sets the current matrix mode.
92 */
vw_MatrixMode(eMatrixMode mode)93 void vw_MatrixMode(eMatrixMode mode)
94 {
95 glMatrixMode(static_cast<GLenum>(mode));
96 }
97
98 /*
99 * Multiply the current matrix by an arbitrary matrix.
100 */
vw_MultMatrix(const GLfloat * matrix)101 void vw_MultMatrix(const GLfloat *matrix)
102 {
103 glMultMatrixf(matrix);
104 }
105
106 /*
107 * Push the current matrix stack.
108 */
vw_PushMatrix()109 void vw_PushMatrix()
110 {
111 glPushMatrix();
112 }
113
114 /*
115 * Pop the current matrix stack.
116 */
vw_PopMatrix()117 void vw_PopMatrix()
118 {
119 glPopMatrix();
120 }
121
122 } // viewizard namespace
123