Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions engine/linux/Makefile.gles
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
EXECUTABLE = shmup
INCLUDES = ../src libpng

linux_SOURCES := native.c main.c
linux_OBJECTS := $(linux_SOURCES:.c=.o)

engine_SOURCES := $(wildcard ../src/*.c)
engine_OBJECTS := $(engine_SOURCES:.c=.o)

libpng_SOURCES := $(wildcard libpng/*.c)
# Do not compile pngtest.c
libpng_SOURCES := $(filter-out libpng/pngtest.c,$(libpng_SOURCES))
libpng_OBJECTS := $(libpng_SOURCES:.c=.o)

CFLAGS += -Wall -Wextra -Wmissing-prototypes -DLINUX $(addprefix -I,$(INCLUDES)) -DGLES -std=gnu99
CFLAGS += `sdl2-config --cflags` `pkg-config zlib --cflags` `pkg-config openal --cflags`
LDFLAGS = -lpthread -ldl -lGLESv1_CM -lm -z `sdl2-config --libs` `pkg-config zlib --libs` `pkg-config openal --libs` -lSDL2_mixer

OBJECTS = $(linux_OBJECTS) $(engine_OBJECTS) $(libpng_OBJECTS)

all: $(EXECUTABLE)

.PHONY: debug
debug: CFLAGS += -g
debug: all

.PHONY: release
release: CFLAGS += -DRELEASE
release: all

shmup: $(OBJECTS)
gcc -o $@ $^ $(LDFLAGS)

%.o: %.c
gcc -o $@ -c $(CFLAGS) $<

.PHONY: clean
clean:
rm -f $(EXECUTABLE) $(OBJECTS)
38 changes: 38 additions & 0 deletions engine/linux/README.gles
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Build requirements:
===================

This code was written and tested using the following libraries and
versions:

* GCC - 4.4.5
* SDL - 2.0
* SDL_mixer - 2.0
* OpenAL - 1.12

The packages in Debian is called:

* libsdl2-2.0-0
* libsdl2-dev
* libsdl2-mixer-2.0-0
* libsdl2-mixer-dev
* libopenal1
* libopenal-dev

Install these in Debian Jessie using:

$ sudo apt-get install libsdl2-2.0 libsdl2-dev libsdl2-mixer-2.0-0 libsdl2-mixer-dev libopenal1 libopenal-dev


Build instructions:
===================

You may need to make changes in the Makefile.

Build a debug binary using (default):

$ make -f Makefile.gles debug

Build a release binary using:

$ make -f Makefile.gles release

98 changes: 96 additions & 2 deletions engine/linux/main.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
#include <string.h>

#ifdef GLES
#include "SDL2/SDL.h"
#else
#include "SDL/SDL.h"
#endif

#include "../src/dEngine.h"
#include "../src/commands.h"
#include "../src/timer.h"
#include "../src/menu.h"
#include "../src/io_interface.h"

#ifndef GLES
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#endif

#ifdef GLES
// SDL2
#define SDL_WM_GrabInput SDL_SetRelativeMouseMode
#define SDL_GRAB_ON SDL_TRUE
#define SDL_GRAB_OFF SDL_FALSE

#include <SDL_opengles2.h>

typedef GLubyte* (APIENTRY * glGetString_Func)(unsigned int);
glGetString_Func glGetStringAPI = NULL;

#endif

int quit = 0;

Expand Down Expand Up @@ -101,7 +120,9 @@ int main(void)
int new_time;
int time_for_frame;
int sleep_time;
#ifndef GLES
SDL_Surface *screen;
#endif
uchar engineParameters = 0;

#ifndef RELEASE
Expand All @@ -112,6 +133,8 @@ int main(void)
setenv("WD", ".", 1);
#endif

#ifndef GLES
// SDL 1.2
SDL_Init(SDL_INIT_EVERYTHING);

SDL_WM_SetCaption("Shmup", NULL);
Expand All @@ -123,8 +146,70 @@ int main(void)

screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_OPENGL);

engineParameters |= GL_11_RENDERER ;
#elif GLES
// SDL 2
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}

SDL_DisplayMode current;
int should_be_zero = SDL_GetCurrentDisplayMode(0, &current);
if(should_be_zero != 0) {
SDL_Log("Could not get display mode for video display 0 %s", SDL_GetError());
}
else {
#define SCREEN_WIDTH current.w
#define SCREEN_HEIGHT current.h
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#ifdef GLES2
// not working at the moment
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#endif
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

SDL_Window* window = SDL_CreateWindow("Shmup", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP);

SDL_GLContext ctx = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, ctx);

glGetStringAPI = (glGetString_Func)SDL_GL_GetProcAddress("glGetString");

SDL_Log("Available renderers:\n");
SDL_Log("\n");
for(int it = 0; it < SDL_GetNumRenderDrivers(); it++) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(it,&info);

SDL_Log("%s\n", info.name);

}
SDL_Log("\n");
SDL_Log("Vendor : %s\n", glGetStringAPI(GL_VENDOR));
SDL_Log("Renderer : %s\n", glGetStringAPI(GL_RENDERER));
SDL_Log("Version : %s\n", glGetStringAPI(GL_VERSION));
SDL_Log("Extensions : %s\n", glGetStringAPI(GL_EXTENSIONS));

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");

#endif

#ifndef GLES
engineParameters |= GL_11_RENDERER ;
#elif GLES
// GLES 2 should be possible but fails to compile shader and with different GL issues right now
#ifdef GLES2
engineParameters |= GL_20_RENDERER ;
#else
engineParameters |= GL_11_RENDERER ;
#endif
#endif
renderer.statsEnabled = 0;
renderer.materialQuality = MATERIAL_QUALITY_HIGH;

Expand All @@ -148,8 +233,15 @@ int main(void)

ReadInput();
dEngine_HostFrame();
#ifndef GLES
// SDL 1.2
SDL_GL_SwapBuffers();
#endif

#ifdef GLES
// SDL 2
SDL_GL_SwapWindow(window);
#endif
new_time = SDL_GetTicks();
time_for_frame = new_time - old_time;
old_time = new_time;
Expand All @@ -159,7 +251,9 @@ int main(void)
if (sleep_time > 0)
SDL_Delay(sleep_time);
}

#ifdef GLES
SDL_DestroyWindow(window);
#endif
SDL_Quit();

return 0;
Expand Down
4 changes: 4 additions & 0 deletions engine/src/renderer_fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@
#elif defined(ANDROID)
#include <GLES/gl.h>
#elif defined(LINUX)
#if !defined(GLES)
#include <GL/gl.h>
#define glOrthof glOrtho
#define glFogx glFogf
#else
#include <GLES/gl.h>
#endif
#endif


Expand Down
6 changes: 3 additions & 3 deletions engine/src/renderer_progr.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "renderer_progr.h"

#include "target.h"
#if defined (SHMUP_TARGET_WINDOWS) || defined (SHMUP_TARGET_MACOSX) || defined (SHMUP_TARGET_LINUX)
#if defined (SHMUP_TARGET_WINDOWS) || defined (SHMUP_TARGET_MACOSX) || defined (SHMUP_TARGET_LINUX) && !defined(GLES2)
void initProgrRenderer(renderer_t* renderer){ Log_Printf("Shader renderer is not implemented.\n");exit(0);}
#else

Expand All @@ -41,7 +41,7 @@ void initProgrRenderer(renderer_t* renderer){ Log_Printf("Shader renderer is not
#include "player.h"
#include "enemy.h"

#if defined(ANDROID)
#if defined(ANDROID) || defined(GLES2)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
Expand Down Expand Up @@ -1127,4 +1127,4 @@ void initProgrRenderer(renderer_t* renderer)
}


#endif
#endif