Browse Source

well, it compiles now

feature/replace-renderer
Martin Dørum 3 years ago
parent
commit
f7b79d94ac

+ 0
- 1
libcygnet/CMakeLists.txt View File

@@ -1,5 +1,4 @@
add_library(libcygnet SHARED
src/Context.cc
src/GlWrappers.cc
src/Renderer.cc
src/ResourceManager.cc

+ 0
- 11
libcygnet/include/cygnet/Context.h View File

@@ -1,11 +0,0 @@
#pragma once

namespace Cygnet {

class Context {
public:
Context();
~Context();
};

}

+ 4
- 0
libcygnet/include/cygnet/Window.h View File

@@ -3,6 +3,8 @@
#include <swan-common/Vector2.h>
#include <memory>

struct SDL_Window;

namespace Cygnet {

struct WindowState;
@@ -18,6 +20,8 @@ public:
void onResize(int w, int h);
SwanCommon::Vec2i size() { return { w_, h_ }; }

SDL_Window *getWindow();

private:
std::unique_ptr<WindowState> state_;
int w_;

+ 0
- 27
libcygnet/src/Context.cc View File

@@ -1,27 +0,0 @@
#include "Context.h"

#include <SDL.h>

#include "util.h"

namespace Cygnet {

Context::Context() {
SDL_Init(SDL_INIT_VIDEO);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);

SDL_GL_SetSwapInterval(1);
}

Context::~Context() {
SDL_Quit();
}

}

+ 13
- 0
libcygnet/src/Window.cc View File

@@ -14,6 +14,15 @@ struct WindowState {

Window::Window(const char *name, int w, int h):
state_(std::make_unique<WindowState>()), w_(w), h_(h) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);

SDL_GL_SetSwapInterval(1);
state_->window = SDL_CreateWindow(name,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE |
@@ -58,4 +67,8 @@ void Window::onResize(int w, int h) {
glCheck();
}

SDL_Window *Window::getWindow() {
return state_->window;
}

}

+ 2
- 2
src/cygnet-test.cc View File

@@ -1,4 +1,3 @@
#include <cygnet/Context.h>
#include <cygnet/Window.h>
#include <cygnet/Renderer.h>
#include <cygnet/ResourceManager.h>
@@ -38,7 +37,7 @@ Cygnet::RenderSprite loadSprite(Cygnet::ResourceBuilder &builder, const char *pa
}

int main() {
Cygnet::Context ctx;
SDL_Init(SDL_INIT_VIDEO);
IMG_Init(IMG_INIT_PNG);
Cygnet::Window win("Cygnet Test", 680, 680);
Cygnet::Renderer rnd;
@@ -178,4 +177,5 @@ int main() {

exit:
IMG_Quit();
SDL_Quit();
}

+ 13
- 26
src/main.cc View File

@@ -10,6 +10,8 @@
#include <string.h>
#include <imgui.h>
#include <imgui_sdl/imgui_sdl.h>
#include <cygnet/Renderer.h>
#include <cygnet/Window.h>

#include <swan/swan.h>

@@ -77,41 +79,31 @@ int main(int argc, char **argv) {
imgassert(IMG_Init(imgFlags) == imgFlags, "Could not initialize SDL_Image");
Deferred<IMG_Quit> sdlImage;

// Create the window
CPtr<SDL_Window, SDL_DestroyWindow> window(
SDL_CreateWindow(
"Project: SWAN",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
(int)(640 * guiScale), (int)(480 * guiScale), winFlags));
Cygnet::Window window("Project: SWAN", 640 * guiScale, 480 * guiScale);

// Load and display application icon
CPtr<SDL_Surface, SDL_FreeSurface> icon(
IMG_Load("assets/icon.png"));
sdlassert(icon, "Could not load icon");
SDL_SetWindowIcon(window.get(), icon.get());

CPtr<SDL_Renderer, SDL_DestroyRenderer> renderer(
SDL_CreateRenderer(window.get(), -1, renderFlags));
sdlassert(renderer, "Could not create renderer");
SDL_SetRenderDrawBlendMode(renderer.get(), SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer.get(), 0, 0, 0, 255);

Win win(window.get(), renderer.get(), guiScale);
SDL_SetWindowIcon(window.getWindow(), icon.get());

// Init ImGUI and ImGUI_SDL
IMGUI_CHECKVERSION();
CPtr<ImGuiContext, ImGui::DestroyContext> context(
ImGui::CreateContext());

/*
ImGuiSDL::Initialize(renderer.get(), (int)win.getPixSize().x, (int)win.getPixSize().y);
Deferred<ImGuiSDL::Deinitialize> imguiSDL;
info << "Initialized with window size " << win.getPixSize();
TODO */

// ImGuiIO is to glue SDL and ImGUI together
ImGuiIO& imguiIO = ImGui::GetIO();
imguiIO.BackendPlatformName = "imgui_sdl + Project: SWAN";

// Create a world
Game game(win);
Game game;
std::vector<std::string> mods{ "core.mod" };
game.createWorld("core::default", mods);

@@ -124,7 +116,6 @@ int main(int argc, char **argv) {
int slowFrames = 0;
while (1) {
ZoneScopedN("game loop");
RTClock totalTimeClock;

SDL_Event evt;
while (SDL_PollEvent(&evt)) {
@@ -137,7 +128,7 @@ int main(int argc, char **argv) {
if (evt.window.event == SDL_WINDOWEVENT_RESIZED) {
imguiIO.DisplaySize.x = (float)evt.window.data1;
imguiIO.DisplaySize.y = (float)evt.window.data2;
win.onResize(evt.window.data1, evt.window.data2);
window.onResize(evt.window.data1, evt.window.data2);
}
break;

@@ -207,7 +198,6 @@ int main(int argc, char **argv) {
}

// Simple case: we can keep up, only need one physics update
RTClock updateClock;
if (dt <= 1 / 25.0) {
ZoneScopedN("game update");
game.update(dt);
@@ -230,14 +220,13 @@ int main(int argc, char **argv) {
while (tickAcc >= 1.0 / TICK_RATE) {
ZoneScopedN("game tick");
tickAcc -= 1.0 / TICK_RATE;
RTClock tickClock;
game.tick(1.0 / TICK_RATE);
}

{
auto [r, g, b, a] = game.backgroundColor();
RenderDrawColor c(renderer.get(), r, g, b, a);
SDL_RenderClear(renderer.get());
//auto [r, g, b, a] = game.backgroundColor();
// TODO: Set clear color
window.clear();
}

// ImGUI
@@ -246,7 +235,6 @@ int main(int argc, char **argv) {

{
ZoneScopedN("game draw");
RTClock drawClock;
game.draw();
}

@@ -257,10 +245,9 @@ int main(int argc, char **argv) {
ImGuiSDL::Render(ImGui::GetDrawData());
}

RTClock presentClock;
{
ZoneScopedN("render present");
SDL_RenderPresent(renderer.get());
window.flip();
}
FrameMark
}

Loading…
Cancel
Save