Skip to content

Commit 930e1ce

Browse files
committed
Fixed all warnings related to use of deprecated OpenGL functions.
1 parent 5ffa014 commit 930e1ce

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_executable(SDLJumpStart
2929
src/engine.cpp
3030
src/font.cpp
3131
src/main.cpp
32+
src/math_stub.cpp
3233
)
3334

3435
# Do you need C++11? Maybe just indicate the features you need like this

src/engine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "AssertMsg.h"
44

55
#include "sdl_gl.h"
6+
#include "math_stub.h"
67

78
// #define _USE_MATH_DEFINES 1
89
#include <math.h>
@@ -88,7 +89,8 @@ Engine::Engine() : font(NULL), sdl_gl_context(NULL), sdl_window(NULL)
8889
glViewport(0, 0, clientW, clientH);
8990
glMatrixMode( GL_PROJECTION );
9091
glLoadIdentity( );
91-
gluPerspective( 60.0, (float)clientW/(float)clientH, 0.00000000001, 1024.0 );
92+
93+
SetGLPerspectiveMat(60.0, (float)clientW/(float)clientH, 0.0001, 1024.0);
9294

9395
font = new FixedWidthBMPFont("images/font.bmp", 16);
9496

@@ -156,7 +158,7 @@ void Engine::Draw()
156158
glViewport(0, 0, clientW, clientH);
157159
glMatrixMode(GL_PROJECTION);
158160
glLoadIdentity();
159-
gluPerspective(60.0, (float)clientW/(float)clientH, 0.0001, 1024.0);
161+
SetGLPerspectiveMat(60.0, (float)clientW/(float)clientH, 0.0001, 1024.0);
160162

161163
glMatrixMode(GL_MODELVIEW);
162164
glLoadIdentity();

src/math_stub.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "math_stub.h"
2+
#include "sdl_gl.h"
3+
4+
#include <cmath>
5+
6+
#define PI_OVER_360 (M_PI/360.0f)
7+
8+
void BuildPerspProjMat(float *m, float fov, float aspect, float znear, float zfar)
9+
{
10+
float f = 1.0f / tan(fov * PI_OVER_360);
11+
12+
m[0] = f / aspect;
13+
m[1] = 0;
14+
m[2] = 0;
15+
m[3] = 0;
16+
17+
m[4] = 0;
18+
m[5] = f;
19+
m[6] = 0;
20+
m[7] = 0;
21+
22+
m[8] = 0;
23+
m[9] = 0;
24+
m[10] = (zfar + znear) / (znear - zfar);
25+
m[11] = -1;
26+
27+
m[12] = 0;
28+
m[13] = 0;
29+
m[14] = 2 * zfar * znear / (znear - zfar);
30+
m[15] = 0;
31+
}
32+
33+
void SetGLPerspectiveMat(float fov, float aspect, float znear, float zfar)
34+
{
35+
float m[16];
36+
BuildPerspProjMat(m, fov, aspect, znear, zfar);
37+
glLoadMatrixf(m);
38+
}

src/math_stub.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef MATH_STUB_H
2+
#define MATH_STUB_H
3+
4+
// Check out the math library I wrote: https://github.com/johnb003/mathing
5+
//
6+
// There's not much point in forcing a reference to a math library for this project, however a math
7+
// lib will inevitably be needed for any real work based on this.
8+
9+
// Here are some basic implementations that can be replaced easily with a math lib.
10+
11+
void BuildPerspProjMat(float *m, float fov, float aspect, float znear, float zfar);
12+
13+
// direct alternative to gluPerspective
14+
void SetGLPerspectiveMat(float fov, float aspect, float znear, float zfar);
15+
16+
#endif // MATH_STUB_H

src/sdl_gl_texture.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ unsigned int LoadTexture(const char *filename, bool mipmapped)
5050
{
5151
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5252
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
53-
gluBuild2DMipmaps(GL_TEXTURE_2D, intFmt, surface->w, surface->h, fmt, GL_UNSIGNED_BYTE, surface->pixels);
5453
}
5554
else
5655
{
5756
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5857
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
59-
glTexImage2D(GL_TEXTURE_2D, 0, intFmt, surface->w, surface->h, 0, fmt, GL_UNSIGNED_BYTE, surface->pixels);
6058
}
59+
60+
glTexImage2D(GL_TEXTURE_2D, 0, intFmt, surface->w, surface->h, 0, fmt, GL_UNSIGNED_BYTE, surface->pixels);
61+
if (mipmapped) glGenerateMipmap(GL_TEXTURE_2D);
6162

6263
SDL_FreeSurface(surface);
6364
return textureIndex;

0 commit comments

Comments
 (0)