aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--include/common.h6
-rw-r--r--include/windowClass.h13
-rw-r--r--src/main.cpp48
-rw-r--r--src/windowClass.cpp40
5 files changed, 47 insertions, 64 deletions
diff --git a/Makefile b/Makefile
index bfb4100..60d784f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
-FLAGS_LINUX = -lGL -lSDL_image
+FLAGS_LINUX = -lGL -lSDL2_image
FLAGS_WIN32 = -lopengl32 -lmingw32 -lSDL2_Image
FLAGS = -m32 -Iinclude -Wall -Werror -lSDL2main -lSDL2
all:
- @g++ src/main.cpp src/UIClass.cpp src/windowClass.cpp src/Quest.cpp -o main $(FLAGS_LINUX) $(FLAGS)
+ @g++ src/*.cpp -o main $(FLAGS_LINUX) $(FLAGS)
win32:
@g++ -L lib/ src/main.cpp src/UIClass.cpp src/windowClass.cpp src/Quest.cpp -o main.exe $(FLAGS_WIN32) $(FLAGS)
diff --git a/include/common.h b/include/common.h
index 56bbe3f..816de5a 100644
--- a/include/common.h
+++ b/include/common.h
@@ -9,10 +9,10 @@
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_opengl.h>
#include <UIClass.h>
-#include <windowClass.h>
+#include <World.h>
-#define SCREEN_WIDTH 1280
-#define SCREEN_HEIGHT 720
+#define SCREEN_WIDTH 640
+#define SCREEN_HEIGHT 480
//#define FULLSCREEN
//SDL VARIABLES
diff --git a/include/windowClass.h b/include/windowClass.h
deleted file mode 100644
index 1aaae98..0000000
--- a/include/windowClass.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef WINDOWCLASS_H
-#define WINDOWCLASS_H
-
-#include <common.h>
-
-class Window{
-public:
- void setupRender();
- void render();
-
-};
-
-#endif //WINDOWCLASS_H \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 71b6595..61920e7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,13 +7,12 @@ SDL_GLContext mainGLContext = NULL;
bool gameRunning = true;
UIClass ui;
-Window win;
int main(int argc,char **argv){
//runs start-up procedures
if(!SDL_Init(SDL_INIT_VIDEO)){
atexit(SDL_Quit);
- if(!(IMG_Init(IMG_INIT_PNG)&IMG_INIT_PNG)){
+ if(!(IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG)&(IMG_INIT_PNG|IMG_INIT_JPG))){
std::cout<<"Could not init image libraries!\n"<<std::endl;
return -1;
}
@@ -41,22 +40,59 @@ int main(int argc,char **argv){
return -1;
}
+ glClearColor(.3,.5,.8,0);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
/**************************
**** GAMELOOP ****
**************************/
- win.setupRender();
+ World *w=new World("res/dirt.jpg",
+ "res/dirt.jpg",
+ "res/dirt.jpg",
+ "res/dirt.jpg");
+
while(gameRunning){
- ui.handleEvents();
- win.render();
+ ui.handleEvents(); // Handle events
+ //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack"
+ //GL_PROJECTION has 2 matrices
+ //GL_MODELVIEW has 32 matrices
+ glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on
+ glPushMatrix(); //push the matrix to the top of the matrix stack
+ glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode
+ //glOrtho(0,SCREEN_WIDTH, 0,SCREEN_HEIGHT, -1,1); //set the the size of the screen
+ glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects
+ glPushMatrix(); //push the matrix to the top of the matrix stack
+ glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode
+ glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on
+ glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack
+
+ /**************************
+ **** RENDER STUFF HERE ****
+ **************************/
+
+ /*glColor3f(1.0f, 0.0f, 0.0f); //color to red
+ glRectf(0,0, 50,50); //draw a test rectangle
+ glColor3f(0.0f, 1.0f, 0.0f); //color to blue
+ glRectf(50,0, 100,50); //draw a test rectangle
+ glColor3f(0.0f, 0.0f, 1.0f); //color to green
+ glRectf(100,0,150,50); //draw a test rectangle*/
+
+ w->draw();
+
+ /**************************
+ **** CLOSE THE LOOP ****
+ **************************/
+
+ glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer
+ SDL_GL_SwapWindow(window); //give the stack to SDL to render it
}
/**************************
**** CLOSE PROGRAM ****
**************************/
-
//closes the window and frees resources
SDL_GL_DeleteContext(mainGLContext);
SDL_DestroyWindow(window);
diff --git a/src/windowClass.cpp b/src/windowClass.cpp
deleted file mode 100644
index e0e3840..0000000
--- a/src/windowClass.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <windowClass.h>
-
-void Window::setupRender(){
- glClearColor(0,0,0,0); //set the background color
-
-}
-
-void Window::render(){
- //a matrix is a blank canvas for the computer to draw on, the matrices are stored in a "stack"
- //GL_PROJECTION has 2 matrices
- //GL_MODELVIEW has 32 matrices
- glMatrixMode(GL_PROJECTION); //set the matrix mode as projection so we can set the ortho size and the camera settings later on
- glPushMatrix(); //push the matrix to the top of the matrix stack
- glLoadIdentity(); //replace the entire matrix stack with the updated GL_PROJECTION mode
-
- glOrtho(0,SCREEN_WIDTH, 0,SCREEN_HEIGHT, -1,1); //set the the size of the screen
-
- glMatrixMode(GL_MODELVIEW); //set the matrix to modelview so we can draw objects
- glPushMatrix(); //push the matrix to the top of the matrix stack
- glLoadIdentity(); //replace the entire matrix stack with the updated GL_MODELVIEW mode
-
- glPushMatrix(); //basically here we put a blank canvas (new matrix) on the screen to draw on
- glClear(GL_COLOR_BUFFER_BIT); //clear the matrix on the top of the stack
-
- /**************************
- **** RENDER STUFF HERE ****
- **************************/
- glColor3f(1.0f, 0.0f, 0.0f); //color to red
- glRectf(0,0, 50,50); //draw a test rectangle
- glColor3f(0.0f, 1.0f, 0.0f); //color to blue
- glRectf(50,0, 100,50); //draw a test rectangle
- glColor3f(0.0f, 0.0f, 1.0f); //color to green
- glRectf(100,0,150,50); //draw a test rectangle
- /**************************
- **** CLOSE THE LOOP ****
- **************************/
-
- glPopMatrix(); //take the matrix(s) off the stack to pass them to the renderer
- SDL_GL_SwapWindow(window); //give the stack to SDL to render it
-} \ No newline at end of file