A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Window.cc 1008B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "Window.h"
  2. #include <SDL_opengles2.h>
  3. #include <assert.h>
  4. namespace Cygnet {
  5. Window::Window(const char *name, int width, int height) {
  6. win_.reset(SDL_CreateWindow(
  7. name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height,
  8. SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE |
  9. SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL));
  10. SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
  11. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  12. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
  13. SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  14. SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
  15. assert(glctx_ = SDL_GL_CreateContext(win_.get()));
  16. makeCurrent();
  17. assert(SDL_GL_SetSwapInterval(1) == 0);
  18. }
  19. Window::~Window() {
  20. SDL_GL_DeleteContext(glctx_);
  21. }
  22. void Window::makeCurrent() {
  23. SDL_GL_MakeCurrent(win_.get(), glctx_);
  24. }
  25. void Window::clear() {
  26. glClearColor(0, 0, 0, 1);
  27. glClear(GL_COLOR_BUFFER_BIT);
  28. }
  29. void Window::flip() {
  30. SDL_GL_SwapWindow(win_.get());
  31. }
  32. }