-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
320 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "EGATexture.h" | ||
#include "defined_gl.h" | ||
#include "segashared\CheckedMemory.h" | ||
#include "segautils\BitTwiddling.h" | ||
|
||
typedef struct EGATexture_t { | ||
GLuint handle; | ||
byte *pixels; | ||
}; | ||
|
||
EGATexture *egaTextureCreate(){ | ||
EGATexture *r = checkedCalloc(1, sizeof(EGATexture)); | ||
r->pixels = checkedCalloc(1, EGA_RES_WIDTH*EGA_RES_HEIGHT * 4); | ||
|
||
glGenTextures(1, &r->handle); | ||
glBindTexture(GL_TEXTURE_2D, r->handle); | ||
glTexImage2D( | ||
GL_TEXTURE_2D, 0, GL_RGBA8, | ||
EGA_RES_WIDTH, EGA_RES_HEIGHT, | ||
0, GL_RGBA, GL_UNSIGNED_BYTE, r->pixels); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||
|
||
glBindTexture(GL_TEXTURE_2D, 0); | ||
|
||
return r; | ||
} | ||
void egaTextureDestroy(EGATexture *self) { | ||
|
||
glDeleteTextures(1, &self->handle); | ||
checkedFree(self->pixels); | ||
checkedFree(self); | ||
} | ||
|
||
static void _updatePixels(EGATexture *self, Frame *frame, byte *palette){ | ||
int x, y, i; | ||
byte *cData = self->pixels; | ||
|
||
for (y = 0; y < EGA_RES_HEIGHT; ++y){ | ||
for (x = 0; x < EGA_RES_WIDTH; ++x) { | ||
|
||
byte color = 0; | ||
byte cbytes[4] = { 0 }; | ||
int colori = 0; | ||
|
||
for (i = 0; i < EGA_PLANES; ++i) { | ||
setBit(&color, i, getBitFromArray(frame->planes[i].lines[y].pixels, x)); | ||
} | ||
|
||
colori = getEGAColor(palette[color]); | ||
memcpy(cbytes, &colori, 4); | ||
|
||
for (i = 0; i < 4; ++i){ | ||
*cData++ = cbytes[i]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void egaTextureRenderFrame(EGATexture *self, Frame *frame, byte *palette){ | ||
_updatePixels(self, frame, palette); | ||
|
||
glFinish(); | ||
glEnable(GL_TEXTURE_2D); | ||
|
||
glBindTexture(GL_TEXTURE_2D, self->handle); | ||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, EGA_RES_WIDTH, EGA_RES_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, self->pixels); | ||
|
||
glBegin(GL_QUADS); | ||
glTexCoord2f(1.0f, 1.0f); glVertex3f(EGA_RES_WIDTH, EGA_RES_HEIGHT, 0.0f); // Bottom Left Of The Texture and Quad | ||
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, EGA_RES_HEIGHT, 0.0f); // Bottom Right Of The Texture and Quad | ||
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); // Top Right Of The Texture and Quad | ||
glTexCoord2f(1.0f, 0.0f); glVertex3f(EGA_RES_WIDTH, 0.0f, 0.0f); // Top Left Of The Texture and Quad | ||
glEnd(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "segalib\EGA.h" | ||
|
||
typedef struct EGATexture_t EGATexture; | ||
|
||
EGATexture *egaTextureCreate(); | ||
void egaTextureDestroy(EGATexture *self); | ||
|
||
void egaTextureRenderFrame(EGATexture *self, Frame *frame, byte *palette); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "defined_gl.h" | ||
#include "OGLRenderer.h" | ||
#include "segashared\CheckedMemory.h" | ||
#include "segalib\EGA.h" | ||
|
||
#include "EGATexture.h" | ||
|
||
|
||
typedef struct { | ||
IRenderer ir; | ||
|
||
EGATexture *tex; | ||
|
||
} OGLRenderer; | ||
|
||
static void _Init(OGLRenderer*); | ||
static void _RenderFrame(OGLRenderer*, Frame *, byte *, Rectf *); | ||
static void _Destroy(OGLRenderer*); | ||
|
||
static IRendererVTable *_getTable() { | ||
static IRendererVTable *r = 0; | ||
if (!r){ | ||
r = calloc(1, sizeof(IRendererVTable)); | ||
r->init = (void(*)(IRenderer*))&_Init; | ||
r->renderFrame = (void(*)(IRenderer*, Frame*, byte*, Rectf *))&_RenderFrame; | ||
r->destroy = (void(*)(IRenderer*))&_Destroy; | ||
} | ||
|
||
return r; | ||
} | ||
|
||
IRenderer *createOGLRenderer(){ | ||
OGLRenderer *r = checkedCalloc(1, sizeof(OGLRenderer)); | ||
r->ir.vTable = _getTable(); | ||
|
||
return (IRenderer *)r; | ||
} | ||
|
||
void _Init(OGLRenderer *self) { | ||
self->tex = egaTextureCreate(); | ||
} | ||
|
||
void _RenderFrame(OGLRenderer *self, Frame *frame, byte *palette, Rectf *vp) { | ||
glViewport((int)vp->left, (int)vp->top, (int)rectfWidth(vp), (int)rectfHeight(vp)); | ||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | ||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
|
||
glMatrixMode(GL_PROJECTION); | ||
glLoadIdentity(); | ||
glOrtho(0, EGA_RES_WIDTH, EGA_RES_HEIGHT, 0, 1.f, -1.f); | ||
|
||
glMatrixMode(GL_MODELVIEW); | ||
glLoadIdentity(); | ||
|
||
egaTextureRenderFrame(self->tex, frame, palette); | ||
} | ||
void _Destroy(OGLRenderer *self){ | ||
if (self->tex){ | ||
egaTextureDestroy(self->tex); | ||
} | ||
checkedFree(self); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "SEGA\IRenderer.h" | ||
#include "segautils\DLLBullshit.h" | ||
|
||
DLL_PUBLIC IRenderer *createOGLRenderer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{8C0896E9-2A31-46AA-9ED8-E97E32199648}</ProjectGuid> | ||
<RootNamespace>OGLRenderer</RootNamespace> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v120</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v120</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<SDLCheck>true</SDLCheck> | ||
<AdditionalIncludeDirectories>../;</AdditionalIncludeDirectories> | ||
<CompileAs>CompileAsC</CompileAs> | ||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BUILDING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<AdditionalDependencies>opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<AdditionalIncludeDirectories>../;</AdditionalIncludeDirectories> | ||
<CompileAs>CompileAsC</CompileAs> | ||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BUILDING_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<AdditionalDependencies>opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClInclude Include="defined_gl.h" /> | ||
<ClInclude Include="EGATexture.h" /> | ||
<ClInclude Include="OGLRenderer.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="EGATexture.c" /> | ||
<ClCompile Include="OGLRenderer.c" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\segalib\segalib.vcxproj"> | ||
<Project>{57b143e8-2941-478d-9873-8fd793813fa2}</Project> | ||
</ProjectReference> | ||
<ProjectReference Include="..\segashared\segashared.vcxproj"> | ||
<Project>{768a8f37-d636-4881-95ea-6ad34e95dc7d}</Project> | ||
</ProjectReference> | ||
<ProjectReference Include="..\segautils\segautils.vcxproj"> | ||
<Project>{c928a7b6-88d1-4697-9e1d-771fa8a06c55}</Project> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="OGLRenderer.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="EGATexture.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="defined_gl.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="OGLRenderer.c"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="EGATexture.c"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifdef _WIN32 | ||
#include <Windows.h> | ||
#include <gl\GL.h> | ||
#else | ||
#include <gl.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters