[win32, wip] simple GL triangle example

This commit is contained in:
martinfouilleul 2023-05-12 16:50:14 +02:00
parent 52538248d9
commit b6db5107a3
1 changed files with 163 additions and 165 deletions

View File

@ -6,7 +6,7 @@
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/
#include<stdlib.h> #include<stdio.h>
#include<string.h> #include<string.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
@ -15,8 +15,6 @@
#define MG_INCLUDE_GL_API #define MG_INCLUDE_GL_API
#include"milepost.h" #include"milepost.h"
#define LOG_SUBSYSTEM "Main"
unsigned int program; unsigned int program;
const char* vshaderSource = const char* vshaderSource =
@ -60,15 +58,13 @@ void compile_shader(GLuint shader, const char* source)
int main() int main()
{ {
LogLevel(LOG_LEVEL_DEBUG);
mp_init(); mp_init();
mp_rect rect = {.x = 100, .y = 100, .w = 800, .h = 600}; mp_rect rect = {.x = 100, .y = 100, .w = 800, .h = 600};
mp_window window = mp_window_create(rect, "test", 0); mp_window window = mp_window_create(rect, "test", 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GL); mg_surface surface = mg_surface_create_for_window(window, MG_GL);
//NOTE: init shader and gl state //NOTE: init shader and gl state
mg_surface_prepare(surface); mg_surface_prepare(surface);
@ -116,10 +112,10 @@ int main()
while(!mp_should_quit()) while(!mp_should_quit())
{ {
mp_pump_events(0); mp_pump_events(0);
mp_event event = {0}; mp_event* event = 0;
while(mp_next_event(&event)) while((event = mp_next_event(mem_scratch())) != 0)
{ {
switch(event.type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case MP_EVENT_WINDOW_CLOSE:
{ {
@ -157,6 +153,8 @@ int main()
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
mg_surface_present(surface); mg_surface_present(surface);
mem_arena_clear(mem_scratch());
} }
mp_terminate(); mp_terminate();