diff --git a/Makefile b/Makefile index 9693127..3460f97 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,7 @@ CC= gcc # Compiler flags CFLAGS= -Wall -Os -std=c99 # Libraries -CLIBS= -# Includes -CINCL= +CLIBS= `sdl-config --cflags` -lSDL -lGL ####### Commands RM= rm -r MKDIR= mkdir -p @@ -29,25 +27,28 @@ SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND)) BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND)) # default task depends on compile -all: compile +all: init compile + +# create object-folder +init: + $(MKDIR) $(OBJDIR) # compile depends on object files and executable compile: $(BINS) $(EXE) # executable depends on all object files $(EXE): $(BINS) - $(CC) $(CINCL) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS) + $(CC) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS) # each file in OBJDIR/*.o depends on corresponding source file in SRCDIR +# $@ = name of target (*.o) +# $< = first dependency (*.c) $(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND) - $(MKDIR) $(OBJDIR) # create object-folder - # $@ = name of target (*.o) - # $< = first dependency (*.c) - $(CC) $(CINCL) -c $< -o $@ $(CFLAGS) + $(CC) -c $< -o $@ $(CLIBS) $(CFLAGS) # delete OUTDIR +# don't raise an error if directory not exists clean: - # don't raise an error if directory not exists $(RM) $(OUTDIR) || true # start programm diff --git a/README.rdoc b/README.rdoc index 551c4f7..cee648d 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,10 +1,20 @@ + == Adventskalender 2009 Viele reden von Open Source, doch die wenigsten beteiligen sich aktiv. Mit dieser Serie von Artikeln will ich den Open Source Gedanken etwas näher bringen und ein interaktives Projekt zum mitmachen schaffen. Verpackt als Adventskalender (in kooperation mit Florian) gibt es jeden zweiten Tag im Advent ein Teil dieser Serie. Florian stellt wiederum jeden zweiten Tag ein CLI-Tool vor. Der Adventskalender ist unter {Florians Blog}[http://feitel.indeedgeek.de/2009/adventskalender/] zu finden. == Über dieses Projekt In diesem Projekt soll (der Anfang) eines kleinen 2D-Spiels erstellt werden. Dieses soll dazu dienen Open Source Entwicklungstools und den Prozess im allgemeinen kennenzulernen. Das Projekt lebt vom Mitmachen, jeder ist herzlich eingeladen sich daran zu beteiligen. +== Vorbedingungen +Folgende Pakete/Programme/Libs sollten im System installiert sein: +* libSDL +* gcc, make + +== Installation +Um das Projekt zu starten, wird das Makefile verwendet. "make" baut das Projekt. + == Teilnehmer * Aaron Mueller * Ruben Mueller * Florian Eitel + diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..e4f8716 --- /dev/null +++ b/src/config.c @@ -0,0 +1,10 @@ + +#include "SDL.h" +#include +#include "config.h" + +// Initialization for the global variables +SDL_Surface *screen = NULL; +SDL_Event event; +bool gameRunning = true; + diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..70b2c70 --- /dev/null +++ b/src/config.h @@ -0,0 +1,19 @@ + +#include +#include "SDL.h" + +// In this file we define all global variables for the whole project. All +// variables definied here can be accessed from all other source files. + +// Global variables and definitions +extern SDL_Surface *screen; // Screen to paint on +extern SDL_Event event; // Event storage +extern bool gameRunning; // Set this variable to false to shutdown the game + + +// Constants + +// Screen size +static const int SCREEN_WIDTH = 800; +static const int SCREEN_HEIGHT = 600; + diff --git a/src/draw.c b/src/draw.c new file mode 100644 index 0000000..5f2ffe4 --- /dev/null +++ b/src/draw.c @@ -0,0 +1,17 @@ + +#include "SDL.h" +#include "draw.h" +#include "config.h" + + +void drawPixel(int x, int y, int color) { + unsigned int *p = (unsigned int*)screen->pixels; + int lineOffset = y * (screen->pitch/4); + p[lineOffset+x] = color; +} + +void drawScreen() { + Uint32 black = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff); + drawPixel(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, black); +} + diff --git a/src/draw.h b/src/draw.h new file mode 100644 index 0000000..afffa65 --- /dev/null +++ b/src/draw.h @@ -0,0 +1,19 @@ + +#ifndef DRAW_H +#define DRAW_H + +/* + * Draw a single pixel on the surface with the given color. This is the basic + * function to paint on the screen. We will be use this function for all paint + * stuff. + */ +void drawPixel(int x, int y, int color); + +/* + * This function will be called for every frame. Here you can actual draw things + * on the screen. + */ +void drawScreen(); + +#endif + diff --git a/src/main.c b/src/main.c index d6ca01e..319fc39 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,29 @@ #include +#include +#include "SDL.h" +#include "config.h" +#include "draw.h" int main(int argc, char **argv) { - printf("Bald kommt der Nikolaus\n"); + // Initialize SDL and open up a screen + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); + + // the main game loop + while (gameRunning == true) { + // Check for events + if (SDL_PollEvent(&event)) { + // Make it possible to close the game window + if (event.type == SDL_QUIT) gameRunning = false; + } + + // Draw the stuff on the screen and "flip" th the next frame + drawScreen(); + SDL_Flip(screen); + } + + SDL_Quit(); return 0; }