openwindow/main.c

62 lines
1.5 KiB
C

#include <stdio.h>
#define GL_GLEXT_PROTOTYPES
#include "GL/gl.h"
#include "src/openwindow.h"
void handleInput(Window * window) {
if (windowKeyPressed(window, WINDOW_KEY_A) && !windowKeyShift(window))
printf("a is being pressed\n");
if (windowKeyHeld(window, WINDOW_KEY_A) && !windowKeyShift(window))
printf("a is being held\n");
if (windowKeyReleased(window, WINDOW_KEY_A) && !windowKeyShift(window))
printf("a is being released\n");
}
int main(void)
{
Window * window = openWindow("Window", 800, 600);
windowSetFps(window, 300);
while (!windowKeyPressed(window, WINDOW_KEY_ESC)) {
windowHandleEvents(window);
handleInput(window);
//printf("fps: %lf\n", 1 / windowGetDeltaTime(window));
//int x = 0;
//int y = 0;
//windowGetMousePosition(window, &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);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, 800, 600);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-0.5, -0.5);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.5, -0.5);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(0.0, 0.5);
glEnd();
glFlush();
windowDraw(window);
}
closeWindow(window);
return 0;
}