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
15 changes: 13 additions & 2 deletions Hurrican/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,19 @@ if (SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIR}
${SDL2_MIXER_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
set(_hur_sdl2 ${SDL2_LIBRARY})
set(_hur_mix ${SDL2_MIXER_LIBRARIES})
set(_hur_img ${SDL2_IMAGE_LIBRARIES})
if (TARGET SDL2::SDL2)
set(_hur_sdl2 SDL2::SDL2)
endif()
if (TARGET SDL2_mixer::SDL2_mixer)
set(_hur_mix SDL2_mixer::SDL2_mixer)
endif()
if (TARGET SDL2_image::SDL2_image)
set(_hur_img SDL2_image::SDL2_image)
endif()
target_link_libraries(${PROJECT_NAME} ${_hur_sdl2} ${_hur_mix} ${_hur_img})
else()
include_directories(${SDL_INCLUDE_DIR}
${SDL_IMAGE_INCLUDE_DIR}
Expand Down
44 changes: 44 additions & 0 deletions Hurrican/darwin/Hurrican-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- @HURRICAN_BUNDLE_VERSION@ substituted at package install. -->
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>hurrican</string>
<key>CFBundleIdentifier</key>
<string>games.hurrican.Hurrican</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Hurrican</string>
<key>CFBundleDisplayName</key>
<string>Hurrican</string>
<key>CFBundleIconFile</key>
<string>Hurrican</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>@HURRICAN_BUNDLE_VERSION@</string>
<key>CFBundleVersion</key>
<string>@HURRICAN_BUNDLE_VERSION@</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
<!-- SDL2 + Cocoa: activation, menu bar, window focus when opened from .app -->
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>NSHumanReadableCopyright</key>
<string>Freeware / OSS Hurrican contributors — see upstream.</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
</dict>
</plist>
Binary file added Hurrican/darwin/Hurrican.icns
Binary file not shown.
4 changes: 4 additions & 0 deletions Hurrican/darwin/make-icon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -eu
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
png2icns "$root/darwin/Hurrican.icns" "$root/data/textures/hurrican_rund.png"
6 changes: 3 additions & 3 deletions Hurrican/data/shaders/320/shader_render.frag
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ void main()
vec4 p;
if (c_color_bleed == 1) {
float pixel_size = 1.0/float(c_WindowWidth)*bleeding_range;
vec4 current_color = texture2D(u_Texture0, xy) * color;
vec4 color_left = texture2D(u_Texture0,vec2(xy.x-pixel_size, xy.y)) * color;
vec4 current_color = texture(u_Texture0, xy) * color;
vec4 color_left = texture(u_Texture0, vec2(xy.x-pixel_size, xy.y)) * color;
p = get_color_bleeding(current_color,color_left);
} else {
p = texture2D(u_Texture0, xy) * color;
p = texture(u_Texture0, xy) * color;
}

/* Add scanlines */
Expand Down
117 changes: 85 additions & 32 deletions Hurrican/src/DX8Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// --------------------------------------------------------------------------------------

#include "DX8Graphics.hpp"
#include <cstdint>
#include <time.h>
#include <algorithm>
#include <stdexcept>
Expand Down Expand Up @@ -50,13 +51,18 @@ float DegreetoRad[360]; // Tabelle mit Rotationswerten
// --------------------------------------------------------------------------------------

DirectGraphicsClass::DirectGraphicsClass() {
glextensions = nullptr;
SupportedETC1 = false;
SupportedPVRTC = false;
use_shader = shader_t::COLOR;

#if defined(USE_GL2) || defined(USE_GL3)
ProgramCurrent = PROGRAM_NONE;
#endif
#if defined(USE_GL3)
StreamVAO = 0;
StreamVBO = 0;
#endif
}

// --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -150,7 +156,14 @@ bool DirectGraphicsClass::Init(std::uint32_t dwBreite, std::uint32_t dwHoehe, st
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#else
/* Desktop GL — USE_GL2 / USE_GL3 (not GLES). */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#if defined(__APPLE__)
/* macOS: request GL 3.2 Core + forward-compatible (needed for GLSL 1.50 shaders). */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#endif
#endif /* defined(USE_GLES1) */
#endif /* SDL_VERSION_ATLEAST(2,0,0) */
#endif // !EGL
Expand Down Expand Up @@ -315,6 +328,16 @@ bool DirectGraphicsClass::Init(std::uint32_t dwBreite, std::uint32_t dwHoehe, st
// --------------------------------------------------------------------------------------

bool DirectGraphicsClass::Exit() {
#if defined(USE_GL3)
if (StreamVBO != 0) {
glDeleteBuffers(1, &StreamVBO);
StreamVBO = 0;
}
if (StreamVAO != 0) {
glDeleteVertexArrays(1, &StreamVAO);
StreamVAO = 0;
}
#endif
#if defined(USE_GL2) || defined(USE_GL3)
Shaders[PROGRAM_COLOR].Close();
Shaders[PROGRAM_TEXTURE].Close();
Expand Down Expand Up @@ -361,7 +384,10 @@ bool DirectGraphicsClass::SetDeviceInfo() {
Protokoll << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
#endif
glextensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
Protokoll << "GL_EXTENSIONS: " << glextensions << std::endl;
if (glextensions != nullptr)
Protokoll << "GL_EXTENSIONS: " << glextensions << std::endl;
else
Protokoll << "GL_EXTENSIONS: (unavailable in Core profile; glGetString(GL_EXTENSIONS) is null)" << std::endl;

#if defined(USE_ETC1)
SupportedETC1 = ExtensionSupported("GL_OES_compressed_ETC1_RGB8_texture");
Expand Down Expand Up @@ -418,7 +444,7 @@ bool DirectGraphicsClass::SetDeviceInfo() {

Shaders[PROGRAM_RENDER].AddConstant("c_WindowWidth", RenderRect.w);
Shaders[PROGRAM_RENDER].AddConstant("c_WindowHeight", RenderRect.h);
Shaders[PROGRAM_RENDER].AddConstant("c_curvature", CommandLineParams.ScreenCurvature ? 1 : 0);
Shaders[PROGRAM_RENDER].AddConstant("c_curvature", CommandLineParams.ScreenCurvature ? 1 : 0);
Shaders[PROGRAM_RENDER].AddConstant("c_color_bleed", CommandLineParams.ColorBleed ? 1 : 0);
Shaders[PROGRAM_RENDER].AddConstant("c_scanlines", CommandLineParams.Scanlines ? 1 : 0);
Shaders[PROGRAM_RENDER].AddConstant("c_noise", CommandLineParams.ScreenNoise ? 1 : 0);
Expand Down Expand Up @@ -578,8 +604,8 @@ void DirectGraphicsClass::RendertoBuffer(GLenum PrimitiveType,
// Check if the program is already in use
if (ProgramCurrent != program_next) {
Shaders[program_next].Use();
if (CommandLineParams.ScreenNoise && (program_next==PROGRAM_RENDER)) {
glUniform1i(NameTime, 50*SDL_GetTicks()/1000);
if (CommandLineParams.ScreenNoise && (program_next == PROGRAM_RENDER)) {
glUniform1i(NameTime, 50 * SDL_GetTicks() / 1000);
}
ProgramCurrent = program_next;
}
Expand All @@ -598,6 +624,9 @@ void DirectGraphicsClass::RendertoBuffer(GLenum PrimitiveType,
return;
}

if (PrimitiveCount == 0)
return;

#if defined(USE_GL1)
// Enable the client states for transfer
if (use_shader == shader_t::TEXTURE) {
Expand All @@ -611,28 +640,47 @@ void DirectGraphicsClass::RendertoBuffer(GLenum PrimitiveType,
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, STRIDE, reinterpret_cast<uint8_t *>(pVertexStreamZeroData) + CLR_OFFSET);
#elif defined(USE_GL2) || defined(USE_GL3)
// Enable attributes and uniforms for transfer
if (is_texture) {
#if defined(USE_ETC1)
if (SupportedETC1) {
glUniform1i(Shaders[ProgramCurrent].texUnit0, 0);
glUniform1i(Shaders[ProgramCurrent].texUnit1, 1);
}
void *ptrPos;
void *ptrClr;
void *ptrTex;
#if defined(USE_GL3)
if (StreamVAO == 0) {
glGenVertexArrays(1, &StreamVAO);
glGenBuffers(1, &StreamVBO);
}
glBindVertexArray(StreamVAO);
glBindBuffer(GL_ARRAY_BUFFER, StreamVBO);
glBufferData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr>(PrimitiveCount) * static_cast<GLsizeiptr>(STRIDE),
pVertexStreamZeroData, GL_STREAM_DRAW);
ptrPos = reinterpret_cast<void *>(static_cast<uintptr_t>(0));
ptrClr = reinterpret_cast<void *>(static_cast<uintptr_t>(CLR_OFFSET));
ptrTex = reinterpret_cast<void *>(static_cast<uintptr_t>(TEX_OFFSET));
#else
uint8_t *const vb = reinterpret_cast<uint8_t *>(pVertexStreamZeroData);
ptrPos = vb;
ptrClr = vb + CLR_OFFSET;
ptrTex = vb + TEX_OFFSET;
#endif
glEnableVertexAttribArray(Shaders[ProgramCurrent].NameTex);
glVertexAttribPointer(Shaders[ProgramCurrent].NameTex, 2, GL_FLOAT, GL_FALSE, STRIDE,
reinterpret_cast<uint8_t *>(pVertexStreamZeroData) + TEX_OFFSET);
if (is_texture) {
#if defined(USE_ETC1)
if (SupportedETC1) {
glUniform1i(Shaders[ProgramCurrent].texUnit0, 0);
glUniform1i(Shaders[ProgramCurrent].texUnit1, 1);
}
#endif
glEnableVertexAttribArray(Shaders[ProgramCurrent].NameTex);
glVertexAttribPointer(Shaders[ProgramCurrent].NameTex, 2, GL_FLOAT, GL_FALSE, STRIDE, ptrTex);
}

glEnableVertexAttribArray(Shaders[ProgramCurrent].NamePos);
glVertexAttribPointer(Shaders[ProgramCurrent].NamePos, 2, GL_FLOAT, GL_FALSE, STRIDE, pVertexStreamZeroData);
glEnableVertexAttribArray(Shaders[ProgramCurrent].NamePos);
glVertexAttribPointer(Shaders[ProgramCurrent].NamePos, 2, GL_FLOAT, GL_FALSE, STRIDE, ptrPos);

glEnableVertexAttribArray(Shaders[ProgramCurrent].NameClr);
glVertexAttribPointer(Shaders[ProgramCurrent].NameClr, 4, GL_UNSIGNED_BYTE, GL_TRUE, STRIDE,
reinterpret_cast<uint8_t *>(pVertexStreamZeroData) + CLR_OFFSET);
glEnableVertexAttribArray(Shaders[ProgramCurrent].NameClr);
glVertexAttribPointer(Shaders[ProgramCurrent].NameClr, 4, GL_UNSIGNED_BYTE, GL_TRUE, STRIDE, ptrClr);

glm::mat4x4 matMVP = matProj * g_matModelView;
glUniformMatrix4fv(Shaders[ProgramCurrent].NameMvp, 1, GL_FALSE, glm::value_ptr(matMVP));
glm::mat4x4 matMVP = matProj * g_matModelView;
glUniformMatrix4fv(Shaders[ProgramCurrent].NameMvp, 1, GL_FALSE, glm::value_ptr(matMVP));
#endif

glDrawArrays(PrimitiveType, 0, PrimitiveCount);
Expand All @@ -646,13 +694,11 @@ void DirectGraphicsClass::RendertoBuffer(GLenum PrimitiveType,
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
#elif defined(USE_GL2) || defined(USE_GL3)
// Disable attributes and uniforms
glDisableVertexAttribArray(Shaders[ProgramCurrent].NamePos);
glDisableVertexAttribArray(Shaders[ProgramCurrent].NameClr);

if (is_texture) {
glDisableVertexAttribArray(Shaders[ProgramCurrent].NameTex);
}
glDisableVertexAttribArray(Shaders[ProgramCurrent].NamePos);
glDisableVertexAttribArray(Shaders[ProgramCurrent].NameClr);
if (is_texture) {
glDisableVertexAttribArray(Shaders[ProgramCurrent].NameTex);
}
#endif
}

Expand All @@ -666,6 +712,11 @@ void DirectGraphicsClass::DisplayBuffer() {
}

bool DirectGraphicsClass::ExtensionSupported(const char *ext) {
if (glextensions == nullptr) {
Protokoll << ext << " is not supported (no GL_EXTENSIONS string in Core profile)" << std::endl;
return false;
}

if (strstr(glextensions, ext) != nullptr) {
Protokoll << ext << " is supported" << std::endl;
return true;
Expand Down Expand Up @@ -832,6 +883,8 @@ void DirectGraphicsClass::SetupFramebuffers() {
{
int tmp_w, tmp_h;
SDL_GetWindowSize(Window, &tmp_w, &tmp_h);
WindowView.x = 0;
WindowView.y = 0;
WindowView.w = tmp_w;
WindowView.h = tmp_h;
}
Expand Down Expand Up @@ -941,22 +994,22 @@ void DirectGraphicsClass::SelectBuffer(bool active) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
void DirectGraphicsClass::FlipSurface(SDL_Surface* surface) {
SDL_LockSurface(surface);

int pitch = surface->pitch; // row size
char* temp = new char[pitch]; // intermediate buffer
char* pixels = static_cast<char*>(surface->pixels);

for(int i = 0; i < surface->h / 2; ++i) {
// get pointers to the two rows to swap
char* row1 = pixels + i * pitch;
char* row2 = pixels + (surface->h - i - 1) * pitch;

// swap rows
memcpy(temp, row1, pitch);
memcpy(row1, row2, pitch);
memcpy(row2, temp, pitch);
}

delete[] temp;

SDL_UnlockSurface(surface);
Expand Down
4 changes: 4 additions & 0 deletions Hurrican/src/DX8Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class DirectGraphicsClass {
#if (defined(USE_GL2) || defined(USE_GL3)) && defined(USE_FBO)
CFbo RenderBuffer;
#endif
#if defined(USE_GL3)
GLuint StreamVAO; /* GL 3 Core: VBO + VAO (no client-side vertex arrays) */
GLuint StreamVBO;
#endif

public:
void ShowBackBuffer(); // Present aufrufen
Expand Down
27 changes: 26 additions & 1 deletion Hurrican/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,35 @@ TexturesystemClass Textures; // DKS - Added Texturesystem class (see DX8
DirectGraphicsClass DirectGraphics; // Grafik-Objekt
DirectInputClass DirectInput; // Input-Objekt
TimerClass Timer; // Timer Klasse für die Framerate

/* Protokoll constructs before main(); keep log path writable */
#if defined(USE_HOME_DIR)
static std::string default_game_log_path() {
std::string base;
if (const char *state = getenv("XDG_STATE_HOME")) {
if (state[0] != '\0')
base = std::string(state) + "/hurrican";
}
if (base.empty()) {
if (const char *home = getenv("HOME")) {
if (home[0] != '\0')
base = std::string(home) + "/.local/state/hurrican";
}
}
if (base.empty())
return std::string("Game_Log.txt");
std::error_code ec;
fs::create_directories(base, ec);
return base + "/Game_Log.txt";
}
#endif

#if defined(__AROS__)
Logdatei Protokoll("T:Game_Log.txt"); // Protokoll Datei
#elif defined(USE_HOME_DIR)
Logdatei Protokoll(default_game_log_path());
#else
Logdatei Protokoll("Game_Log.txt"); // Protokoll Datei
Logdatei Protokoll("Game_Log.txt"); // Protokoll Datei (current directory)
#endif
SoundManagerClass SoundManager; // Sound Manager
DirectGraphicsFont *pDefaultFont = new (DirectGraphicsFont);
Expand Down
9 changes: 9 additions & 0 deletions Hurrican/src/SDLPort/cfbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ bool CFbo::Open(uint16_t w, uint16_t h) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

#if defined(USE_GLES2) || defined(USE_GLES3)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, nullptr);
#else
/* Desktop: RGB565 FBO color targets can read back black on Apple GL. */
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
#endif
/* Create the framebuffer reference */
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
Expand Down Expand Up @@ -100,6 +106,9 @@ bool CFbo::Open(uint16_t w, uint16_t h) {

void CFbo::BindTexture(bool active) {
if (active) {
#if defined(USE_GL2) || defined(USE_GL3)
glActiveTexture(GL_TEXTURE0);
#endif
glBindTexture(GL_TEXTURE_2D, texture);
#if defined(USE_GL1)
glEnable(GL_TEXTURE_2D);
Expand Down
Loading