Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
7343a95a45 | |||
62568e3252 | |||
668d7869fe | |||
7320f07d0e | |||
364504ae5c | |||
0d3e714f52 | |||
bfd4f6e187 | |||
98a04a15b2 | |||
adda18b0cc | |||
0d937b48d7 | |||
9dd30ff8bd | |||
31c31e925e | |||
38f3fc615a | |||
611da9f3ec | |||
8d445554ba | |||
af93b712aa | |||
5ae78b473c | |||
f1e6d00c4a |
@@ -122,13 +122,13 @@ enum class MOUSEBUTTONCODE {
|
||||
|
||||
class RWindowEvent {
|
||||
private:
|
||||
std::chrono::milliseconds timestamp;
|
||||
std::chrono::high_resolution_clock::time_point timePoint;
|
||||
public:
|
||||
long timeStamp();
|
||||
std::chrono::high_resolution_clock::time_point timeStamp();
|
||||
virtual ~RWindowEvent() = default;
|
||||
virtual bool empty();
|
||||
RWindowEvent() {
|
||||
timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
timePoint = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
};
|
||||
const RWindowEvent EmptyRWindowEvent;
|
||||
|
@@ -31,7 +31,8 @@ private:
|
||||
public:
|
||||
bool getFlag(RWindowFlags flag);
|
||||
void setFlag(RWindowFlags flag, bool state);
|
||||
void init(RenderingAPI api, const char* title, int width, int height);
|
||||
void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
|
||||
static void setVsyncEnabled(bool b);
|
||||
void destroyWindow();
|
||||
void pollEvents();
|
||||
void setSize(int width, int height);
|
||||
|
8
main.cpp
8
main.cpp
@@ -2,11 +2,15 @@
|
||||
#include "include/rewindow/types/window.h"
|
||||
int main() {
|
||||
auto* window = new(RWindow);
|
||||
window->init(RenderingAPI::OPENGL, "name",100,100);
|
||||
window->init(RenderingAPI::OPENGL, "name",1152,864, false);
|
||||
window->setFlag(RWindowFlags::RESIZABLE, false);
|
||||
int i;
|
||||
while (true) {
|
||||
if (i <= 10)
|
||||
window->pollEvents();
|
||||
|
||||
window->glSwapBuffers();
|
||||
i++;
|
||||
std::cout << i << std::endl;
|
||||
if (window->keyDown(SCANCODE::A)) {
|
||||
std::cout << "A" << std::endl;
|
||||
std::cout << (int64_t) window->getEvent(SCANCODE::A).empty() << std::endl;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "../include/rewindow/types/event.h"
|
||||
bool RWindowEvent::empty() {
|
||||
if (this->timestamp == EmptyRWindowEvent.timestamp || this->timestamp == EmptyKeyDownEvent.timestamp || this->timestamp == EmptyMouseButtonDownEvent.timestamp)
|
||||
if (timePoint == EmptyRWindowEvent.timePoint || this->timePoint == EmptyKeyDownEvent.timePoint || this->timePoint == EmptyMouseButtonDownEvent.timePoint)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
long RWindowEvent::timeStamp() {
|
||||
return timestamp.count();
|
||||
std::chrono::high_resolution_clock::time_point RWindowEvent::timeStamp() {
|
||||
return timePoint;
|
||||
}
|
||||
|
@@ -1,29 +1,29 @@
|
||||
#include <iostream>
|
||||
#include "rewindow/types/window.h"
|
||||
|
||||
bool vsync = false;
|
||||
Window window;
|
||||
XEvent xev;
|
||||
Display* display = XOpenDisplay(nullptr);
|
||||
int defaultScreen = DefaultScreen(display);
|
||||
//Visual* visual = DefaultVisual(display,defaultScreen);
|
||||
XVisualInfo* visual;
|
||||
//int depth = DefaultDepth(display, defaultScreen);
|
||||
XSetWindowAttributes xSetWindowAttributes;
|
||||
XWindowAttributes windowAttributes;
|
||||
Atom wmDeleteWindow;
|
||||
XSizeHints hints;
|
||||
GLXContext glContext;
|
||||
PFNGLXSWAPINTERVALEXTPROC _glXSwapIntervalEXT = nullptr; //It causes issues if it's named just "glXSwapIntervalEXT".
|
||||
|
||||
void RWindow::init(RenderingAPI api, const char* title, int width, int height) {
|
||||
void RWindow::init(RenderingAPI api, const char* title, int width, int height, bool sync) {
|
||||
if (api == RenderingAPI::OPENGL) {
|
||||
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
|
||||
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
GLint glAttributes[] = {GLX_CONTEXT_MAJOR_VERSION_ARB, 1, GLX_CONTEXT_MINOR_VERSION_ARB, 4, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||
visual = glXChooseVisual(display, defaultScreen, glAttributes);
|
||||
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
|
||||
vsync = sync;
|
||||
xSetWindowAttributes.colormap = XCreateColormap(display, RootWindow(display, defaultScreen), visual->visual,
|
||||
AllocNone);
|
||||
|
||||
@@ -40,6 +40,7 @@ void RWindow::init(RenderingAPI api, const char* title, int width, int height) {
|
||||
wmDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(display, window, &wmDeleteWindow, 1);
|
||||
glXMakeCurrent(display, window, glContext);
|
||||
setVsyncEnabled(vsync);
|
||||
} else {exit(0);}
|
||||
}
|
||||
|
||||
@@ -199,3 +200,9 @@ void RWindow::glSwapBuffers() {
|
||||
glXSwapBuffers(display,window);
|
||||
}
|
||||
|
||||
void RWindow::setVsyncEnabled(bool b) {
|
||||
vsync = b;
|
||||
_glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
|
||||
_glXSwapIntervalEXT(display, window, vsync);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user