vsync test
This commit is contained in:
@@ -154,7 +154,8 @@ public:
|
||||
void setMouseCenter();
|
||||
void restoreMouseFromLastCenter(); // Feels nicer for users
|
||||
|
||||
void setFocused(bool);
|
||||
|
||||
static void setVsyncEnabled(bool b);
|
||||
void setFullscreen(bool fs);
|
||||
void setResizable(bool resizable);
|
||||
void setVsyncEnabled(bool);
|
||||
@@ -165,7 +166,7 @@ public:
|
||||
|
||||
bool getFlag(RWindowFlags flag) const;
|
||||
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);
|
||||
void destroyWindow();
|
||||
void pollEvents();
|
||||
void refresh();
|
||||
|
4
main.cpp
4
main.cpp
@@ -30,8 +30,12 @@ int main() {
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
||||
{
|
||||
|
@@ -49,13 +49,13 @@ bool Key::operator<(const Key &rhs) const {
|
||||
void RWindow::raise() const { XRaiseWindow(display, window); }
|
||||
void RWindow::lower() const { XLowerWindow(display, window); }
|
||||
|
||||
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 vsync) {
|
||||
if (api == RenderingAPI::OPENGL) {
|
||||
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
|
||||
xSetWindowAttributes.override_redirect = True;
|
||||
xSetWindowAttributes.event_mask = ExposureMask;
|
||||
|
||||
setVsyncEnabled(vsync);
|
||||
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||
visual = glXChooseVisual(display, defaultScreen, glAttributes);
|
||||
glContext = glXCreateContext(display, visual, nullptr, GL_TRUE);
|
||||
@@ -323,3 +323,9 @@ void RWindow::restoreFromFullscreen() {
|
||||
SubstructureNotifyMask | SubstructureRedirectMask, &xev);
|
||||
}
|
||||
|
||||
void RWindow::setVsyncEnabled(bool b) {
|
||||
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = nullptr;
|
||||
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
|
||||
glXSwapIntervalEXT(display, None, b);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user