Skip to content

Commit ca2bbd6

Browse files
authored
Merge pull request #14 from dclamage/openarl-latest
Merged changes from Openarl's latest codebase that he provided.
2 parents 367d5b3 + be041b4 commit ca2bbd6

File tree

19 files changed

+281
-123
lines changed

19 files changed

+281
-123
lines changed

SimpleGraphic.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.960
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30907.101
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleGraphic", "SimpleGraphic.vcxproj", "{62A6B2C3-84CC-49CC-BAD7-DD0A4BFE05CB}"
77
EndProject

engine/core.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SimpleGraphic Engine
2+
// (c) David Gowor, 2014
3+
//
4+
// Core Global Header
5+
//
6+
7+
// =======
8+
// Headers
9+
// =======
10+
11+
#include "core/core_config.h"
12+
#include "core/core_video.h"
13+
14+
#include "core/core_main.h"
15+

engine/core/core_main.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
#include "common.h"
88
#include "system.h"
9-
10-
#include "core_config.h"
11-
#include "core_video.h"
12-
13-
#include "core_main.h"
9+
#include "core.h"
1410

1511
#include "ui.h"
1612

@@ -32,8 +28,6 @@ class core_main_c: public core_IMain {
3228

3329
sys_IMain* sys = nullptr;
3430

35-
core_IConfig* config = nullptr;
36-
core_IVideo* video = nullptr;
3731
ui_IMain* ui = nullptr;
3832

3933
bool initialised = false;
@@ -63,26 +57,22 @@ void core_main_c::Init(int argc, char** argv)
6357
{
6458
// Initialise config system
6559
config = core_IConfig::GetHandle(sys);
60+
video = core_IVideo::GetHandle(sys);
6661

6762
// Initialise UI Manager
68-
ui = ui_IMain::GetHandle(sys, config);
63+
ui = ui_IMain::GetHandle(sys, this);
6964
ui->Init(argc, argv);
7065
sys->con->ExecCommands(true);
7166

7267
// Hide the sysconsole
7368
sys->conWin->SetVisible(false);
74-
75-
// Initialise video
76-
video = core_IVideo::GetHandle(sys);
77-
video->Apply();
69+
sys->video->SetForeground();
7870

7971
initialised = true;
8072
}
8173

8274
void core_main_c::Frame()
8375
{
84-
// sys->con->Printf("Messages...\n");
85-
8676
// Execute commands
8777
sys->con->ExecCommands();
8878

@@ -94,16 +84,12 @@ void core_main_c::Shutdown()
9484
{
9585
initialised = false;
9686

97-
// Shutdown video
98-
sys->video->SetVisible(false);
99-
video->Save();
100-
core_IVideo::FreeHandle(video);
101-
10287
// Shutdown UI Manager
10388
ui->Shutdown();
10489
ui_IMain::FreeHandle(ui);
10590

10691
// Shutdown config system
92+
core_IVideo::FreeHandle(video);
10793
core_IConfig::FreeHandle(config);
10894

10995
sys->con->Printf("Engine shutdown complete.\n");

engine/core/core_main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class core_IMain {
1414
static core_IMain* GetHandle(sys_IMain* sysHnd);
1515
static void FreeHandle(core_IMain* hnd);
1616

17+
core_IConfig* config = nullptr;
18+
core_IVideo* video = nullptr;
19+
1720
virtual void Init(int argc, char** argv) = 0;
1821
virtual void Frame() = 0;
1922
virtual void Shutdown() = 0;

engine/render.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ enum r_texFlag_e {
3333
TF_ASYNC = 0x08 // Asynchronous loading
3434
};
3535

36+
// Blend modes
37+
enum r_blendMode_e {
38+
RB_ALPHA,
39+
RB_PRE_ALPHA,
40+
RB_ADDITIVE
41+
};
42+
3643
// Shader handle
3744
class r_shaderHnd_c {
3845
friend class r_renderer_c;
@@ -71,6 +78,7 @@ class r_IRenderer {
7178
virtual void SetDrawSubLayer(int subLayer) = 0;
7279
virtual int GetDrawLayer() = 0;
7380
virtual void SetViewport(int x = 0, int y = 0, int width = 0, int height = 0) = 0;
81+
virtual void SetBlendMode(int mode) = 0;
7482
virtual void DrawColor(const col4_t col = NULL) = 0;
7583
virtual void DrawColor(dword col) = 0;
7684
virtual void DrawImage(r_shaderHnd_c* hnd, float x, float y, float w, float h, float s1 = 0.0f, float t1 = 0.0f, float s2 = 1.0f, float t2 = 1.0f) = 0;

engine/render/r_main.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ r_shaderHnd_c::~r_shaderHnd_c()
9393
struct r_layerCmd_s {
9494
enum {
9595
VIEWPORT,
96+
BLEND,
9697
BIND,
9798
COLOR,
9899
QUAD,
99100
} cmd;
100101
union {
101102
r_viewport_s viewport;
103+
int blendMode;
102104
r_tex_c* tex;
103-
GLenum mode;
104105
col4_t col;
105106
struct {
106107
double s[4];
@@ -150,6 +151,13 @@ void r_layer_c::SetViewport(r_viewport_s* viewport)
150151
cmd->viewport.height = viewport->height;
151152
}
152153

154+
void r_layer_c::SetBlendMode(int mode)
155+
{
156+
r_layerCmd_s* cmd = NewCommand();
157+
cmd->cmd = r_layerCmd_s::BLEND;
158+
cmd->blendMode = mode;
159+
}
160+
153161
void r_layer_c::Bind(r_tex_c* tex)
154162
{
155163
r_layerCmd_s* cmd = NewCommand();
@@ -177,6 +185,7 @@ void r_layer_c::Quad(double s0, double t0, double x0, double y0, double s1, doub
177185
void r_layer_c::Render()
178186
{
179187
r_viewport_s curViewPort = {-1, -1, -1, -1};
188+
int curBlendMode = -1;
180189
r_tex_c* curTex = NULL;
181190
for (int i = 0; i < numCmd; i++) {
182191
r_layerCmd_s* cmd = cmdList[i];
@@ -191,6 +200,21 @@ void r_layer_c::Render()
191200
glLoadIdentity();
192201
}
193202
break;
203+
case r_layerCmd_s::BLEND:
204+
if (cmd->blendMode != curBlendMode) {
205+
switch (cmd->blendMode) {
206+
case RB_ALPHA:
207+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
208+
break;
209+
case RB_PRE_ALPHA:
210+
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
211+
break;
212+
case RB_ADDITIVE:
213+
glBlendFunc(GL_ONE, GL_ONE);
214+
break;
215+
}
216+
}
217+
break;
194218
case r_layerCmd_s::BIND:
195219
if (cmd->tex != curTex) {
196220
cmd->tex->Bind();
@@ -278,7 +302,6 @@ void r_renderer_c::Init()
278302
glEnable(GL_TEXTURE_2D);
279303
glDisable(GL_DEPTH_TEST);
280304
glEnable(GL_BLEND);
281-
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
282305

283306
// Load extensions
284307
sys->con->Printf("Loading OpenGL extensions...\n");
@@ -372,11 +395,12 @@ void r_renderer_c::Shutdown()
372395

373396
void r_renderer_c::BeginFrame()
374397
{
375-
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
398+
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
376399

377400
curLayer = layerList[0];
378401

379402
SetViewport();
403+
SetBlendMode(RB_ALPHA);
380404
DrawColor();
381405
}
382406

@@ -585,6 +609,7 @@ void r_renderer_c::SetDrawLayer(int layer, int subLayer)
585609
}
586610
curLayer = newCurLayer;
587611
curLayer->SetViewport(&curViewport);
612+
curLayer->SetBlendMode(curBlendMode);
588613
}
589614

590615
void r_renderer_c::SetDrawSubLayer(int subLayer)
@@ -610,6 +635,12 @@ void r_renderer_c::SetViewport(int x, int y, int width, int height)
610635
curLayer->SetViewport(&curViewport);
611636
}
612637

638+
void r_renderer_c::SetBlendMode(int mode)
639+
{
640+
curBlendMode = mode;
641+
curLayer->SetBlendMode(mode);
642+
}
643+
613644
void r_renderer_c::DrawColor(const col4_t col)
614645
{
615646
if (col) {

engine/render/r_main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class r_layer_c {
3636
~r_layer_c();
3737

3838
void SetViewport(r_viewport_s* viewport);
39+
void SetBlendMode(int mode);
3940
void Bind(r_tex_c* tex);
4041
void Color(col4_t col);
4142
void Quad(double s0, double t0, double x0, double y0, double s1, double t1, double x1, double y1, double s2, double t2, double x2, double y2, double s3, double t3, double x3, double y3);
@@ -69,6 +70,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
6970
void SetDrawSubLayer(int subLayer);
7071
int GetDrawLayer();
7172
void SetViewport(int x = 0, int y = 0, int width = 0, int height = 0);
73+
void SetBlendMode(int mode);
7274
void DrawColor(const col4_t col = NULL);
7375
void DrawColor(dword col);
7476
void DrawImage(r_shaderHnd_c* hnd, float x, float y, float w, float h, float s1 = 0.0f, float t1 = 0.0f, float s2 = 1.0f, float t2 = 1.0f);
@@ -108,6 +110,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
108110
col4_t drawColor = {}; // Current draw color
109111

110112
r_viewport_s curViewport; // Current viewport
113+
int curBlendMode = 0; // Current blend mode
111114

112115
int numShader = 0;
113116
class r_shader_c *shaderList[R_MAXSHADERS] = {};

engine/system/sys_console.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class sys_IConsole {
1414
static sys_IConsole* GetHandle(class sys_IMain* sysHnd);
1515
static void FreeHandle(sys_IConsole* hnd);
1616

17-
virtual void SetVisible( bool show ) = 0; // Set window state
17+
virtual void SetVisible(bool show) = 0; // Set window state
1818
virtual bool IsVisible() = 0; // Get window state
19+
virtual void SetForeground() = 0; // Bring window to foreground if shown
1920
virtual void SetTitle(const char* title) = 0; // Set window title
2021
};

engine/system/sys_video.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class sys_IVideo {
5050
virtual int Apply(sys_vidSet_s* set) = 0; // Apply settings
5151

5252
virtual void SetActive(bool active) = 0; // Respond to window activated status change
53+
virtual void SetForeground() = 0; // Activate the window if shown
5354
virtual bool IsActive() = 0; // Get activated status
5455
virtual void SizeChanged(int width, int height, bool max) = 0; // Respond to window size change
5556
virtual void PosChanged(int x, int y) = 0; // Respond to window position change

engine/system/win/sys_console.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class sys_console_c: public sys_IConsole, public conPrintHook_c, public thread_c
2525
// Interface
2626
void SetVisible(bool show);
2727
bool IsVisible();
28+
void SetForeground();
2829
void SetTitle(const char* title);
2930

3031
// Encapsulated
@@ -223,6 +224,13 @@ void sys_console_c::SetVisible(bool show)
223224
}
224225
}
225226

227+
void sys_console_c::SetForeground()
228+
{
229+
if (shown) {
230+
SetForegroundWindow(hwMain);
231+
}
232+
}
233+
226234
bool sys_console_c::IsVisible()
227235
{
228236
return IsWindowVisible(hwMain);

0 commit comments

Comments
 (0)