aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/je_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics/je_window.cpp')
-rw-r--r--src/libjin/Graphics/je_window.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp
index f0b789e..c14d290 100644
--- a/src/libjin/Graphics/je_window.cpp
+++ b/src/libjin/Graphics/je_window.cpp
@@ -3,15 +3,18 @@
#include <iostream>
+#include "../common/je_exception.h"
#include "../utils/je_utils.h"
#include "../audio/sdl/je_sdl_audio.h"
#include "../utils/je_log.h"
-#include "shader/je_shader.h"
+#include "shaders/je_shader.h"
#include "je_window.h"
#include "je_gl.h"
#include "je_canvas.h"
+using namespace JinEngine::Graphics::Shaders;
+
namespace JinEngine
{
namespace Graphics
@@ -19,9 +22,7 @@ namespace JinEngine
bool Window::initSystem(const SettingBase* s)
{
- #if defined(jin_debug)
- Loghelper::log(Loglevel::LV_INFO, "Init window system");
- #endif
+ jin_log_info("Initialize window system.");
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return false;
@@ -30,8 +31,9 @@ namespace JinEngine
mSize.w = setting->width;
mSize.h = setting->height;
mFps = setting->fps;
- bool vsync = setting->vsync;
- const char* title = setting->title;
+ bool vsync = setting->vsync;
+ const char* title = setting->title;
+ const char* icon = setting->icon;
if (mWnd)
{
@@ -58,34 +60,51 @@ namespace JinEngine
int wx = SDL_WINDOWPOS_UNDEFINED,
wy = SDL_WINDOWPOS_UNDEFINED;
- int flag = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
+ int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag);
if (mWnd == NULL)
return false;
+
+ // Set window icon
+ try
+ {
+ Bitmap* bitmap = Bitmap::createBitmap(icon);
+ SDL_Surface *surface;
+ Color* pixels = const_cast<Color*>(bitmap->getPixels());
+ uint w = bitmap->getWidth(), h = bitmap->getHeight();
+ surface = SDL_CreateRGBSurfaceFrom(
+ pixels, w, h, 32, w * 4, Color::RMASK, Color::GMASK, Color::BMASK, Color::AMASK);
+ SDL_SetWindowIcon(mWnd, surface);
+ SDL_FreeSurface(surface);
+ } catch (...) {}
+
ctx = SDL_GL_CreateContext(mWnd);
if (ctx == NULL)
return false;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
SDL_GL_MakeCurrent(mWnd, ctx);
- // default configuration
+ // Default configuration
gl.setClearColor(0, 0, 0, 0xff);
- gl.pushColor(0xff, 0xff, 0xff, 0xff);
+ glClear(GL_COLOR_BUFFER_BIT);
+ gl.pushColor(0xff, 0xff, 0xff, 0xff);
gl.enable(GL_BLEND);
gl.enable(GL_TEXTURE_2D);
gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- // avoid white screen blink on windows
- swapBuffers();
- // bind to default canvas
+ // Bind to default canvas
Canvas::unbind();
Shader::unuse();
+ // Avoid white blinnk.
+ swapBuffers();
+
return true;
}
void Window::quitSystem()
{
+ jin_log_info("Quit window system.");
// disable opengl
gl.disable(GL_BLEND);
gl.disable(GL_TEXTURE_2D);