example.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "glplatform.h"
  2. #include "glplatform-glcore.h"
  3. #include <stdlib.h>
  4. bool fullscreen = false;
  5. void on_expose(struct glplatform_win *win)
  6. {
  7. glClearColor(0,0,1,1);
  8. glClear(GL_COLOR_BUFFER_BIT);
  9. glplatform_swap_buffers(win);
  10. }
  11. void on_key_down(struct glplatform_win *win, int k)
  12. {
  13. //TODO: No fullscreen support for windows yet
  14. #ifndef _WIN32
  15. if (k == 'f') {
  16. fullscreen = !fullscreen;
  17. glplatform_fullscreen_win(win, fullscreen);
  18. }
  19. #endif
  20. }
  21. void on_destroy(struct glplatform_win *win)
  22. {
  23. glplatform_destroy_window(win);
  24. }
  25. int main()
  26. {
  27. struct glplatform_win_callbacks cb = {
  28. .on_expose = on_expose,
  29. .on_destroy = on_destroy,
  30. .on_key_down = on_key_down
  31. };
  32. if (!glplatform_init()) {
  33. exit(-1);
  34. }
  35. struct glplatform_win *win = glplatform_create_window("Hello window", &cb, NULL, 512, 512);
  36. if (!win)
  37. exit(-1);
  38. glplatform_show_window(win);
  39. glplatform_gl_context_t ctx = glplatform_create_context(win, 3, 3);
  40. if (!ctx)
  41. exit(-1);
  42. glplatform_make_current(win, ctx);
  43. if (!glplatform_glcore_init(3, 3)) {
  44. exit(-1);
  45. }
  46. while (glplatform_process_events()) {
  47. if (glplatform_get_events(true) < 0)
  48. break;
  49. }
  50. }