Files
biomed/main.cpp
2026-02-12 10:51:02 +01:00

157 lines
5.0 KiB
C++

#include "screen.h"
#include <SDL2/SDL_opengl.h>
#include "application.h"
//#include "console.h"
//#include "interpreter.h"
//#include "worker.h"
//#include "layout.h"
//#include "texture.h"
//#include "turtle.h"
//#include "keystrokes.h"
#include "GUI.h"
#include "GUIMouse.h"
#include "GUIKeyboard.h"
#include "font.h"
#include "GUIViewport.h"
#include "Editor.h"
#include "texture.h"
int main(int argc, const char* argv[])
{
// SDL INIT
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { puts("SDL_Init error"); return -1; }
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_Window* gWindow = SDL_CreateWindow("BiomED", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (gWindow == NULL) { puts("SDL_CreateWindow error"); return -1; }
SDL_GLContext gContext = SDL_GL_CreateContext(gWindow);
if (gContext == NULL) { puts("SDL_GL_CreateContext error"); return -1; }
if (SDL_GL_SetSwapInterval(1) < 0) { puts("WARNING: no vsync!"); }
// OPENGL INIT
glClearColor(0.12f, 0.12f, 0.12f, 1.0f);
glDisable(GL_DEPTH_TEST);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable(GL_NORMALIZE);
glEnable(GL_CULL_FACE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_LIGHT0);
//static const GLfloat LightPosition[]= {0.408248f, 0.408248f, -0.816497f, 0.0f};//{ 0.5f, 0.5f, 1.0f, 0.0f }; // 5 4 2 0
static const GLfloat LightPosition[]= {0, 0, -1.0f, 0.0f};//{ 0.5f, 0.5f, 1.0f, 0.0f }; // 5 4 2 0
static const GLfloat LightAmbient[]= { 0.2f, 0.2f, 0.2f, 1.0f };
static const GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
// SUBSYSTEMS INIT
//Console::Init();
//Worker::RegisterCommands();
//Layout::Load("_last", SILENT);
//Texture::texture = Texture::Create();
//Turtle::Clear();
Editor::texture = Texture::Create(32, 32);
for (int i = 0; i < 32*32*4; i++) Editor::bitmap[i] = 255;
Texture::Update(Editor::texture, 32, 32, Editor::bitmap);
Font* f = new Font();
f->Load("font");
viewports[1].rotation = {0,0};
// MAIN LOOP
SDL_Event e;
while (not Application::ShouldQuit()) {
// SDL EVENTS
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
Application::Quit();
} else if (e.type == SDL_WINDOWEVENT) {
if (e.window.event == SDL_WINDOWEVENT_RESIZED) {
SCREEN_WIDTH = e.window.data1;
SCREEN_HEIGHT = e.window.data2;
//GUIElement::root->SetSize(Vector2(e.window.data1, e.window.data2));
//} else if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
// GUIState::NeedsRedraw();
}
} else if (e.type == SDL_MOUSEMOTION) {
GUIMouse::ReceiveMouseMoveEvent(e.motion.x, e.motion.y);
} else if (e.type == SDL_MOUSEBUTTONDOWN) {
GUIMouse::Button b = e.button.button == 1 ? GUIMouse::Button::Left : e.button.button == 2 ? GUIMouse::Button::Middle : GUIMouse::Button::Right;
GUIMouse::ReceiveMouseDownEvent(b);
} else if (e.type == SDL_MOUSEBUTTONUP) {
GUIMouse::Button b = e.button.button == 1 ? GUIMouse::Button::Left : e.button.button == 2 ? GUIMouse::Button::Middle : GUIMouse::Button::Right;
GUIMouse::ReceiveMouseUpEvent(b);
} else if (e.type == SDL_KEYDOWN) {
GUIKeyboard::ReceiveKeyboardEvent(e.key.keysym.sym);
} else if (e.type == SDL_KEYUP) {
GUIKeyboard::ReceiveKeyboardEvent(SDLK_UNKNOWN);
} else if (e.type == SDL_MOUSEWHEEL) {
GUIMouse::ReceiveMouseWheelEvent(e.wheel.x, e.wheel.y);
} else if (e.type == SDL_MULTIGESTURE) {
printf("GESTURE: %.2f, %.2f, %i\n", e.mgesture.dTheta*100, e.mgesture.dDist*100, e.mgesture.numFingers);
GUIMouse::ReceiveMultigestureEvent(e.mgesture.dTheta, e.mgesture.dDist, e.mgesture.numFingers);
}
/*if (Console::Enable(QUERY)) {
if (e.type == SDL_TEXTINPUT) {
Console::PutChar(toupper(e.text.text[0]));
//printf("%c",e.text.text[0]);
} else if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_RETURN) {
char command[80];
Console::Enter(command);
Worker::ExecuteCommand(Interpreter::Do(command));
} else if (e.key.keysym.sym == SDLK_BACKSPACE) {
Console::DelChar();
} else if (e.key.keysym.sym == SDLK_UP) {
Console::PrevComm();
} else if (e.key.keysym.sym == SDLK_DOWN) {
Console::NextComm();
}
}
} else {
if (e.type == SDL_KEYDOWN) {
Keystrokes::KeyPressed(e.key.keysym.sym);
}
}*/
}
// DRAW
if (Application::NeedsUpdate(0)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//GUIState::Update();
GUI::Draw();
//Layout::Draw();
//Console::Draw();
SDL_GL_SwapWindow(gWindow);
glClearColor(0.12f, 0.12f, 0.12f, 1.0f);
Application::Updated();
GUIMouse::Reset();
GUIKeyboard::Reset();
}
}
//Layout::Save("_last");
}