added windowGetSize
This commit is contained in:
parent
8b228295b9
commit
5d6503e804
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ all: libopenwindow.so libopenwindow.dll
|
||||||
|
|
||||||
libopenwindow.so: glad_linux.a
|
libopenwindow.so: glad_linux.a
|
||||||
mkdir -p ${OUTPUT}
|
mkdir -p ${OUTPUT}
|
||||||
gcc ${FLAGS} -o ${OUTPUT}libopenwindow.so ${LINUX_FILES} -lX11 -lGLX -lOpenGL
|
gcc ${FLAGS} -o ${OUTPUT}libopenwindow.so ${LINUX_FILES} -lX11 -lGLX -lOpenGL -lgallium
|
||||||
|
|
||||||
libopenwindow.dll: glad_windows.a
|
libopenwindow.dll: glad_windows.a
|
||||||
mkdir -p ${OUTPUT}
|
mkdir -p ${OUTPUT}
|
||||||
|
|
28
main.c
28
main.c
|
@ -1,5 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#include "GL/gl.h"
|
#include "GL/gl.h"
|
||||||
|
|
||||||
#include "src/openwindow.h"
|
#include "src/openwindow.h"
|
||||||
|
@ -17,22 +18,27 @@ void handleInput(Window * window) {
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
Window * w = openWindow("Window", 800, 600);
|
Window * window = openWindow("Window", 800, 600);
|
||||||
|
|
||||||
windowSetFps(w, 300);
|
windowSetFps(window, 300);
|
||||||
|
|
||||||
while (!windowKeyPressed(w, WINDOW_KEY_ESC)) {
|
while (!windowKeyPressed(window, WINDOW_KEY_ESC)) {
|
||||||
windowHandleEvents(w);
|
windowHandleEvents(window);
|
||||||
|
|
||||||
handleInput(w);
|
handleInput(window);
|
||||||
|
|
||||||
//printf("fps: %lf\n", 1 / windowGetDeltaTime(w));
|
//printf("fps: %lf\n", 1 / windowGetDeltaTime(window));
|
||||||
|
|
||||||
int x = 0;
|
//int x = 0;
|
||||||
int y = 0;
|
//int y = 0;
|
||||||
windowGetMousePosition(w, &x, &y);
|
//windowGetMousePosition(window, &x, &y);
|
||||||
//printf("x: %d, y: %d\n", x, y);
|
//printf("x: %d, y: %d\n", x, y);
|
||||||
|
|
||||||
|
int w = 0;
|
||||||
|
int h = 0;
|
||||||
|
windowGetSize(window, &w, &h);
|
||||||
|
printf("%dx%d\n", w, h);
|
||||||
|
|
||||||
glClearColor(0.1, 0.2, 0.3, 1);
|
glClearColor(0.1, 0.2, 0.3, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glViewport(0, 0, 800, 600);
|
glViewport(0, 0, 800, 600);
|
||||||
|
@ -46,10 +52,10 @@ int main(void)
|
||||||
glEnd();
|
glEnd();
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
windowDraw(w);
|
windowDraw(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeWindow(w);
|
closeWindow(window);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,10 @@ void windowDefaultEventHandler(Window * w, XEvent xev) {
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
w->io.mouse.current[xev.xbutton.button - 1] = false;
|
w->io.mouse.current[xev.xbutton.button - 1] = false;
|
||||||
break;
|
break;
|
||||||
|
case ConfigureNotify:
|
||||||
|
w->width = xev.xconfigure.width;
|
||||||
|
w->height = xev.xconfigure.height;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,10 +227,15 @@ double windowGetDeltaTime(Window *window) {
|
||||||
return window->dt.dt;
|
return window->dt.dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void windowGetSize(Window * window, int * width, int * height) {
|
||||||
|
*width = window->width;
|
||||||
|
*height = window->height;
|
||||||
|
}
|
||||||
|
|
||||||
void windowDraw(Window * window) {
|
void windowDraw(Window * window) {
|
||||||
glXSwapBuffers(window->x.display, window->x.window);
|
glXSwapBuffers(window->x.display, window->x.window);
|
||||||
|
|
||||||
usleep(((float)1 / (window->fps + 1)) * 1e6);
|
usleep(((float)1 / window->fps) * 1e6);
|
||||||
clock_gettime(CLOCK_MONOTONIC, window->dt.t2);
|
clock_gettime(CLOCK_MONOTONIC, window->dt.t2);
|
||||||
|
|
||||||
window->dt.dt = (double) (window->dt.t2->tv_sec - window->dt.t1->tv_sec) + (window->dt.t2->tv_nsec - window->dt.t1->tv_nsec) / 1e9;
|
window->dt.dt = (double) (window->dt.t2->tv_sec - window->dt.t1->tv_sec) + (window->dt.t2->tv_nsec - window->dt.t1->tv_nsec) / 1e9;
|
||||||
|
@ -504,7 +513,7 @@ double windowGetDeltaTime(Window * window) {
|
||||||
void windowDraw(Window * window) {
|
void windowDraw(Window * window) {
|
||||||
SwapBuffers(window->wgl.display);
|
SwapBuffers(window->wgl.display);
|
||||||
|
|
||||||
Sleep((uint32_t)(((double)1 / (window->fps + 1)) * 1e3));
|
Sleep((uint32_t)(((double)1 / window->fps) * 1e3));
|
||||||
|
|
||||||
QueryPerformanceFrequency(&window->dt.freq);
|
QueryPerformanceFrequency(&window->dt.freq);
|
||||||
QueryPerformanceCounter(&window->dt.t2);
|
QueryPerformanceCounter(&window->dt.t2);
|
||||||
|
|
|
@ -71,6 +71,8 @@ typedef struct Window {
|
||||||
X11 x;
|
X11 x;
|
||||||
WindowDeltaTime dt;
|
WindowDeltaTime dt;
|
||||||
uint32_t fps;
|
uint32_t fps;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
} Window;
|
} Window;
|
||||||
|
|
||||||
#define WINDOW_KEY_Q ("q")
|
#define WINDOW_KEY_Q ("q")
|
||||||
|
@ -156,6 +158,8 @@ typedef struct Window {
|
||||||
WGL wgl;
|
WGL wgl;
|
||||||
WindowDeltaTime dt;
|
WindowDeltaTime dt;
|
||||||
uint32_t fps;
|
uint32_t fps;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
} Window;
|
} Window;
|
||||||
|
|
||||||
#define WINDOW_KEY_Q ('Q')
|
#define WINDOW_KEY_Q ('Q')
|
||||||
|
@ -212,6 +216,7 @@ bool windowKeyAlt(Window * window);
|
||||||
Window * openWindow(const char * name, size_t width, size_t height);
|
Window * openWindow(const char * name, size_t width, size_t height);
|
||||||
void windowSetFps(Window * window, uint32_t fps);
|
void windowSetFps(Window * window, uint32_t fps);
|
||||||
double windowGetDeltaTime(Window * window);
|
double windowGetDeltaTime(Window * window);
|
||||||
|
void windowGetSize(Window * window, int * width, int * height);
|
||||||
void windowGetMousePosition(Window * window, int * x, int * y);
|
void windowGetMousePosition(Window * window, int * x, int * y);
|
||||||
void windowDraw(Window * window);
|
void windowDraw(Window * window);
|
||||||
void windowHandleEvents(Window * window);
|
void windowHandleEvents(Window * window);
|
||||||
|
|
Loading…
Reference in New Issue