Skip to content

Commit b42f010

Browse files
committed
Added basic window creation.
1 parent 9d30eef commit b42f010

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
*.lai
1212
*.la
1313
*.a
14+
15+
checkers-spike

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export OBJ_HOME := $(realpath obj)
2+
export SRC_HOME := $(realpath src)
3+
export INCL_HOME := $(realpath include)
4+
EXECUTABLE := checkers-spike
5+
ALLFILES := $(wildcard $(SRC_HOME)/*) $(wildcard $(INCL_HOME)/*)
6+
export CXX := g++ -c
7+
export LD := g++
8+
export CXXFLAGS := -g -I$(INCL_HOME) -std=gnu++0x
9+
export LDFLAGS := -lSDL2 -lGL -lGLU
10+
11+
.PHONY: all
12+
all: $(EXECUTABLE)
13+
14+
$(EXECUTABLE): $(ALLFILES)
15+
cd src && $(MAKE)
16+
${LD} obj/*.o $(LDFLAGS) -o $(EXECUTABLE)

obj/.keepthis

Whitespace-only changes.

src/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SOURCES := $(wildcard *.cpp)
2+
OBJECTS := $(addprefix $(OBJ_HOME)/, $(SOURCES:.cpp=.o))
3+
HEADERS := $(wildcard $(INCL_HOME)/*.h)
4+
5+
.PHONY: main
6+
main: $(OBJECTS)
7+
8+
$(OBJ_HOME)/%.o: %.cpp $(HEADERS)
9+
$(CXX) $(CXXFLAGS) $< -o $@

src/main.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <iostream>
2+
3+
#include <SDL2/SDL.h>
4+
#include <SDL2/SDL_opengl.h>
5+
6+
7+
void initOpenGL() {
8+
glEnable(GL_DEPTH_TEST);
9+
glEnable(GL_TEXTURE_2D);
10+
glEnable (GL_BLEND);
11+
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
12+
}
13+
14+
/* function to reset our viewport after a window resize */
15+
int updateViewport( int width, int height ) {
16+
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
17+
glMatrixMode(GL_PROJECTION);
18+
glLoadIdentity ();
19+
gluOrtho2D(0, 1, 0, 1);
20+
21+
glMatrixMode(GL_MODELVIEW);
22+
}
23+
24+
void render(SDL_Renderer* displayRenderer) {
25+
26+
27+
SDL_RenderPresent(displayRenderer);
28+
}
29+
30+
31+
int
32+
main(int argc, char *argv[])
33+
{
34+
SDL_Init(SDL_INIT_VIDEO);
35+
SDL_Window* displayWindow;
36+
SDL_Renderer* displayRenderer;
37+
SDL_RendererInfo displayRendererInfo;
38+
SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_OPENGL, &displayWindow, &displayRenderer);
39+
SDL_GetRendererInfo(displayRenderer, &displayRendererInfo);
40+
/*TODO: Check that we have OpenGL */
41+
if ((displayRendererInfo.flags & SDL_RENDERER_ACCELERATED) == 0 ||
42+
(displayRendererInfo.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
43+
/*TODO: Handle this. We have no render surface and not accelerated. */
44+
std::cout << "Unable to create a window using accelerated graphics." << std::endl;
45+
}
46+
47+
48+
initOpenGL();
49+
50+
updateViewport(800, 600);
51+
52+
render(displayRenderer);
53+
54+
55+
SDL_Delay(5000);
56+
SDL_Quit();
57+
58+
return 0;
59+
}

0 commit comments

Comments
 (0)