From 7795dd729d2486c7d720d73b5380d6235b0a3994 Mon Sep 17 00:00:00 2001 From: Aloshi <aloshi@aloshi> Date: Mon, 10 Sep 2012 13:48:00 -0500 Subject: [PATCH] Added missing new files to the repo. --- Makefile.x86 | 18 ++++++++ src/Renderer_init.cpp | 9 ++++ src/Renderer_init_sdlgl.cpp | 92 +++++++++++++++++++++++++++++++++++++ src/platform.h | 13 ++++++ 4 files changed, 132 insertions(+) create mode 100644 Makefile.x86 create mode 100644 src/Renderer_init.cpp create mode 100644 src/Renderer_init_sdlgl.cpp create mode 100644 src/platform.h diff --git a/Makefile.x86 b/Makefile.x86 new file mode 100644 index 000000000..bdc77a712 --- /dev/null +++ b/Makefile.x86 @@ -0,0 +1,18 @@ +CC=g++ +CFLAGS=-c -Wall -I/usr/include/freetype2 -I/usr/include/SDL -I/usr/include -D_DESKTOP_ +LDFLAGS=-lGL -lfreetype -lSDL -lboost_system -lboost_filesystem -lfreeimage +SRCSOURCES=main.cpp Renderer.cpp Renderer_init.cpp Font.cpp Renderer_draw_gl.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp MathExp.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp components/GuiTheme.cpp pugiXML/pugixml.cpp +SOURCES=$(addprefix src/,$(SRCSOURCES)) +OBJECTS=$(SOURCES:.cpp=.o) +EXECUTABLE=emulationstation + +all: $(SOURCES) $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + +.cpp.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -rf src/*o src/components/*o $(EXECUTABLE) diff --git a/src/Renderer_init.cpp b/src/Renderer_init.cpp new file mode 100644 index 000000000..4fa90d4fc --- /dev/null +++ b/src/Renderer_init.cpp @@ -0,0 +1,9 @@ +#include "platform.h" + +#ifdef _RPI_ + #include "Renderer_init_rpi.cpp" +#endif + +#ifdef _DESKTOP_ + #include "Renderer_init_sdlgl.cpp" +#endif diff --git a/src/Renderer_init_sdlgl.cpp b/src/Renderer_init_sdlgl.cpp new file mode 100644 index 000000000..c00ab07e7 --- /dev/null +++ b/src/Renderer_init_sdlgl.cpp @@ -0,0 +1,92 @@ +#include "Renderer.h" +#include <iostream> +#include "platform.h" +#include GLHEADER +#include "Font.h" +#include <SDL/SDL.h> + +namespace Renderer +{ + unsigned int display_width = 0, display_height = 0; + + SDL_Surface* sdlScreen = NULL; + + bool createSurface() //unsigned int display_width, unsigned int display_height) + { + std::cout << "Creating surface...\n"; + + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) + { + std::cerr << "Error initializing SDL!\n"; + return false; + } + + 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_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | SDL_FULLSCREEN); + + if(sdlScreen == NULL) + { + std::cout << "Error creating SDL video surface!\n"; + return false; + } + + //usually display width/height are not specified, i.e. zero, which SDL automatically takes as "native resolution" + //so, since other things rely on the size of the screen (damn currently unnormalized coordinate system), we set it here + //even though the system was already initialized + display_width = sdlScreen->w; + display_height = sdlScreen->h; + + std::cout << "Success!\n"; + + return true; + } + + void swapBuffers() + { + SDL_GL_SwapBuffers(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + void destroySurface() + { + SDL_FreeSurface(sdlScreen); + sdlScreen = NULL; + SDL_Quit(); + } + + bool init(int w, int h) + { + if(w) + display_width = w; + if(h) + display_height = h; + + bool createdSurface = createSurface(); + + if(!createdSurface) + return false; + + Font::initLibrary(); + + glViewport(0, 0, display_width, display_height); + glOrtho(0, display_width, display_height, 0, -1.0, 1.0); + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + + onInit(); + + return true; + } + + void unloadFonts(); //defined in Renderer_draw_gl.cpp + void deinit() + { + onDeinit(); + + unloadFonts(); + destroySurface(); + } +}; diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 000000000..7074f61a6 --- /dev/null +++ b/src/platform.h @@ -0,0 +1,13 @@ +//the Makefiles define these via command line +//#define _RPI_ +//#define _DESKTOP_ + + +#ifdef _RPI_ + #define GLHEADER <GLES/gl.h> +#endif + + +#ifdef _DESKTOP_ + #define GLHEADER <GL/gl.h> +#endif