Skip to content

Commit

Permalink
Added ogl1.1 support! :D
Browse files Browse the repository at this point in the history
  • Loading branch information
britown88 committed Nov 15, 2014
1 parent dacd83e commit 04a0c06
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 4 deletions.
4 changes: 2 additions & 2 deletions BT/BT.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<ProjectReference Include="..\BTGame\BTGame.vcxproj">
<Project>{81713ca5-bcec-450c-9d78-edac6c7b71d1}</Project>
</ProjectReference>
<ProjectReference Include="..\GLSLRenderer\GLSLRenderer.vcxproj">
<Project>{8917fdbe-ca46-4d6a-93e4-57a0ffd0df08}</Project>
<ProjectReference Include="..\OGLRenderer\OGLRenderer.vcxproj">
<Project>{8c0896e9-2a31-46aa-9ed8-e97e32199648}</Project>
</ProjectReference>
<ProjectReference Include="..\segalib\segalib.vcxproj">
<Project>{57b143e8-2941-478d-9873-8fd793813fa2}</Project>
Expand Down
4 changes: 2 additions & 2 deletions BT/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "SEGA\App.h"
#include "BTGame\BT.h"
#include "segashared\CheckedMemory.h"
#include "GLSLRenderer\GLSLRenderer.h"
#include "OGLRenderer\OGLRenderer.h"

int main()
{
runApp(btCreate(), createGLSLRenderer());
runApp(btCreate(), createOGLRenderer());
printMemoryLeaks();

return 0;
Expand Down
77 changes: 77 additions & 0 deletions OGLRenderer/EGATexture.c
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();

}
12 changes: 12 additions & 0 deletions OGLRenderer/EGATexture.h
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);


62 changes: 62 additions & 0 deletions OGLRenderer/OGLRenderer.c
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);
}
4 changes: 4 additions & 0 deletions OGLRenderer/OGLRenderer.h
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();
97 changes: 97 additions & 0 deletions OGLRenderer/OGLRenderer.vcxproj
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>
36 changes: 36 additions & 0 deletions OGLRenderer/OGLRenderer.vcxproj.filters
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>
6 changes: 6 additions & 0 deletions OGLRenderer/defined_gl.h
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
22 changes: 22 additions & 0 deletions SEGA.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BTGame", "BTGame\BTGame.vcx
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SEGA Studio", "SEGA Studio\SEGA Studio.vcxproj", "{C806DDE1-8AFC-4F81-82B6-1A89F366EF79}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLRenderer", "OGLRenderer\OGLRenderer.vcxproj", "{8C0896E9-2A31-46AA-9ED8-E97E32199648}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Renderers", "Renderers", "{79A0BD00-E188-42B5-9183-1CC12F8C2DA1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libsega", "libsega", "{4DBDC669-51A3-4736-A6F1-440A4ABB6BDC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Runnables", "Runnables", "{131F5133-564A-4D7A-BB51-6E1F6B5E4189}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down Expand Up @@ -70,8 +78,22 @@ Global
{C806DDE1-8AFC-4F81-82B6-1A89F366EF79}.Debug|Win32.Build.0 = Debug|Win32
{C806DDE1-8AFC-4F81-82B6-1A89F366EF79}.Release|Win32.ActiveCfg = Release|Win32
{C806DDE1-8AFC-4F81-82B6-1A89F366EF79}.Release|Win32.Build.0 = Release|Win32
{8C0896E9-2A31-46AA-9ED8-E97E32199648}.Debug|Win32.ActiveCfg = Debug|Win32
{8C0896E9-2A31-46AA-9ED8-E97E32199648}.Debug|Win32.Build.0 = Debug|Win32
{8C0896E9-2A31-46AA-9ED8-E97E32199648}.Release|Win32.ActiveCfg = Release|Win32
{8C0896E9-2A31-46AA-9ED8-E97E32199648}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{57B143E8-2941-478D-9873-8FD793813FA2} = {4DBDC669-51A3-4736-A6F1-440A4ABB6BDC}
{9FC3C5BB-1685-4C31-91A5-B98FE8903D9F} = {4DBDC669-51A3-4736-A6F1-440A4ABB6BDC}
{2F441A33-903C-4503-89C5-359BB137260C} = {131F5133-564A-4D7A-BB51-6E1F6B5E4189}
{C928A7B6-88D1-4697-9E1D-771FA8A06C55} = {4DBDC669-51A3-4736-A6F1-440A4ABB6BDC}
{8917FDBE-CA46-4D6A-93E4-57A0FFD0DF08} = {79A0BD00-E188-42B5-9183-1CC12F8C2DA1}
{768A8F37-D636-4881-95EA-6AD34E95DC7D} = {4DBDC669-51A3-4736-A6F1-440A4ABB6BDC}
{C806DDE1-8AFC-4F81-82B6-1A89F366EF79} = {131F5133-564A-4D7A-BB51-6E1F6B5E4189}
{8C0896E9-2A31-46AA-9ED8-E97E32199648} = {79A0BD00-E188-42B5-9183-1CC12F8C2DA1}
EndGlobalSection
EndGlobal

0 comments on commit 04a0c06

Please sign in to comment.