opengl-cpp/src/sdl.hpp

55 lines
1.3 KiB
C++
Raw Normal View History

2025-01-05 01:30:18 +00:00
#pragma once
#include <SDL2/SDL.h>
#include <string>
2025-01-05 02:41:40 +00:00
// Include the OpenGL headers (these may vary by system)
#if defined(__APPLE__)
#include <OpenGL/gl3.h> // On macOS, <OpenGL/gl3.h> is often used
#else
#include <GL/glew.h> // or <glad/glad.h> if using GLAD
#endif
//#include <iostream>
2025-01-05 01:30:18 +00:00
// Forward declaration of classes and structs if needed
// class SomethingElse;
class SdlWindow {
public:
// Constructor
SdlWindow(const char* title, int width, int height);
2025-01-05 01:30:18 +00:00
// Destructor
~SdlWindow();
2025-01-05 01:30:18 +00:00
// Run the main loop
void run();
unsigned int compileShader(unsigned int type, const std::string& source);
unsigned int createShader(const std::string& vetexShader, const std::string& fragmentShader);
2025-01-05 01:30:18 +00:00
void setFullscreen(bool fullscreen);
2025-01-05 01:30:18 +00:00
private:
// Private data members
SDL_Window* m_window;
SDL_Renderer* m_renderer;
bool m_isRunning;
bool m_isFullscreen;
int m_width;
int m_height;
int m_windowedWidth; // stored width before fullscreen
int m_windowedHeight; // stored height before fullscreen
SDL_GLContext m_glContext;
// temp shader stuff
std::string vetexShader;
std::string fragmentShader;
unsigned int shader;
// Private methods
void processEvents();
void update();
void render();
2025-01-05 01:30:18 +00:00
};