summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authoriamn1ck <iamn1ck@yahoo.com>2017-02-19 07:00:34 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:22:46 -0600
commit74c6854fd8dcbaee736ac0421805ff1e03c4a1e2 (patch)
tree4a3ae40bea9b07a2111128e98d9272bdbac2af87 /src/window.cpp
parent03885192b9ff7d3c5e2dcfd98aefd21e9b62f603 (diff)
-quadtree and opengl rendering are now in the master branch !
-using sdl_rect for location and size ended up being not so great due to it not having floats, so we reverted back to using location -much, much refractoring is now needed
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/window.cpp b/src/window.cpp
index f7868a4..28af6bf 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,31 +1,41 @@
#include "window.hpp"
-Window::Window()
+Window::Window(int width, int height, const std::string& title)
{
- SDL_Init(SDL_INIT_VIDEO);
- main = SDL_CreateWindow("main",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,WINDOW_X,WINDOW_Y,SDL_WINDOW_SHOWN);
- renderer = SDL_CreateRenderer(main,-1,SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
+ SDL_Init(SDL_INIT_EVERYTHING);
+
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+ main = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,SDL_WINDOW_OPENGL);
+ glContext = SDL_GL_CreateContext(main);
+ GLenum status = glewInit();
+ closed = false;
+
+ if(status != GLEW_OK)
+ std::cerr << "Failiure to init." << std::endl;
+
}
-void Window::Destroy()
+Window::~Window()
{
- SDL_DestroyRenderer(renderer);
+ SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(main);
SDL_Quit();
}
-void Window::Clear()
+void Window::swapBuffers()
{
- SDL_RenderClear(renderer);
+ SDL_GL_SwapWindow(main);
}
-void Window::Render()
+void Window::Clear(float r, float g, float b, float a)
{
- SDL_RenderPresent(renderer);
+ glClearColor(r, g, b, a);
+ glClear(GL_COLOR_BUFFER_BIT);
}
-SDL_Renderer* Window::getRenderer()
-{
- return renderer;
-}