Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from gilmorem560/develop
Browse files Browse the repository at this point in the history
Almost Real Camera Update
  • Loading branch information
Matthew Gilmore authored Apr 24, 2020
2 parents 7a0f1f2 + 250dbcc commit ba5e5db
Show file tree
Hide file tree
Showing 36 changed files with 1,710 additions and 444 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
/TODO

# Visual Studio Files
/OpenGL/x64/Debug
/x64/Debug
/x64/Release
*.db
*.suo
*.opendb
Expand Down
17 changes: 16 additions & 1 deletion game-template.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<CompileAs>CompileAsC</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -134,16 +135,22 @@
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\graphics\objects\actor.c" />
<ClCompile Include="src\graphics\objects\collision_index.c" />
<ClCompile Include="src\graphics\objects\hedrons.c" />
<ClCompile Include="src\graphics\objects\prisms.c" />
<ClCompile Include="src\graphics\objects\scene.c" />
<ClCompile Include="src\graphics\objects\texture.c" />
<ClCompile Include="src\graphics\primitives\collision\collision_box.c" />
<ClCompile Include="src\graphics\primitives\collision\collision_router.c" />
<ClCompile Include="src\graphics\primitives\grid2d.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Default</CompileAs>
</ClCompile>
Expand Down Expand Up @@ -171,29 +178,37 @@
<ClCompile Include="src\input\wglevent.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Default</CompileAs>
</ClCompile>
<ClCompile Include="src\modes\actor_test.c" />
<ClCompile Include="src\modes\diamond.c" />
<ClCompile Include="src\modes\map.c" />
<ClCompile Include="src\modes\sandbox.c" />
<ClCompile Include="src\modes\scene_test.c" />
<ClCompile Include="src\modes\stage.c" />
<ClCompile Include="src\util\veccomp.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\assets\assets.h" />
<ClInclude Include="src\graphics\contexts\glcontext.h" />
<ClInclude Include="src\graphics\objects\actor.h" />
<ClInclude Include="src\graphics\objects\collision_index.h" />
<ClInclude Include="src\graphics\objects\hedrons.h" />
<ClInclude Include="src\graphics\objects\prisms.h" />
<ClInclude Include="src\graphics\objects\scene.h" />
<ClInclude Include="src\graphics\objects\texture.h" />
<ClInclude Include="src\graphics\primitives\collision.h" />
<ClInclude Include="src\graphics\primitives\coord.h" />
<ClInclude Include="src\graphics\primitives\prim.h" />
<ClInclude Include="src\graphics\contexts\wglcontext.h" />
<ClInclude Include="src\input\input.h" />
<ClInclude Include="src\modes\actor_test.h" />
<ClInclude Include="src\modes\diamond.h" />
<ClInclude Include="src\modes\map.h" />
<ClInclude Include="src\modes\modes.h" />
<ClInclude Include="src\modes\sandbox.h" />
<ClInclude Include="src\modes\scene_test.h" />
<ClInclude Include="src\modes\stage.h" />
<ClInclude Include="src\util\macros.h" />
<ClInclude Include="src\util\veccomp.h" />
</ItemGroup>
<ItemGroup>
<None Include="data\textures\rgba_font.bin" />
Expand Down
45 changes: 45 additions & 0 deletions game-template.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<Filter Include="Resource Files\data\textures">
<UniqueIdentifier>{a58543b1-e451-49f9-8eeb-58b7a45fa8d0}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\util">
<UniqueIdentifier>{1e656dd0-50ee-4d6a-aecb-1fb3b9f7a250}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\util">
<UniqueIdentifier>{854bd0cd-243c-4e01-b9c2-5102dc972d40}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main.c">
Expand Down Expand Up @@ -99,6 +105,27 @@
<ClCompile Include="src\graphics\objects\texture.c">
<Filter>Source Files\obj</Filter>
</ClCompile>
<ClCompile Include="src\graphics\primitives\collision\collision_box.c">
<Filter>Source Files\obj\prim</Filter>
</ClCompile>
<ClCompile Include="src\graphics\primitives\collision\collision_router.c">
<Filter>Source Files\obj\prim</Filter>
</ClCompile>
<ClCompile Include="src\graphics\objects\actor.c">
<Filter>Source Files\obj</Filter>
</ClCompile>
<ClCompile Include="src\graphics\objects\collision_index.c">
<Filter>Source Files\obj</Filter>
</ClCompile>
<ClCompile Include="src\graphics\objects\prisms.c">
<Filter>Source Files\obj</Filter>
</ClCompile>
<ClCompile Include="src\util\veccomp.c">
<Filter>Source Files\util</Filter>
</ClCompile>
<ClCompile Include="src\modes\actor_test.c">
<Filter>Source Files\mode</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\input\input.h">
Expand Down Expand Up @@ -149,6 +176,24 @@
<ClInclude Include="src\graphics\objects\texture.h">
<Filter>Header Files\obj</Filter>
</ClInclude>
<ClInclude Include="src\util\veccomp.h">
<Filter>Header Files\util</Filter>
</ClInclude>
<ClInclude Include="src\graphics\objects\actor.h">
<Filter>Header Files\obj</Filter>
</ClInclude>
<ClInclude Include="src\graphics\objects\collision_index.h">
<Filter>Header Files\obj</Filter>
</ClInclude>
<ClInclude Include="src\graphics\objects\prisms.h">
<Filter>Header Files\obj</Filter>
</ClInclude>
<ClInclude Include="src\graphics\primitives\collision.h">
<Filter>Header Files\obj</Filter>
</ClInclude>
<ClInclude Include="src\modes\actor_test.h">
<Filter>Header Files\mode</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="data\textures\rgba_font.bin">
Expand Down
5 changes: 2 additions & 3 deletions game-template.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>2&gt;&amp;1</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerDebuggerType>Auto</LocalDebuggerDebuggerType>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>2&gt; &amp;1</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>2&gt;&amp;1</LocalDebuggerCommandArguments>
</PropertyGroup>
</Project>
14 changes: 10 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
bin_PROGRAMS = main
main_SOURCES = \
graphics/contexts/glxcontext.c \
graphics/objects/actor.c \
graphics/objects/collision_index.c \
graphics/objects/hedrons.c \
graphics/objects/prisms.c \
graphics/objects/scene.c \
graphics/objects/texture.c \
graphics/primitives/collision/collision_box.c \
graphics/primitives/collision/collision_router.c \
graphics/primitives/grid2d.c \
graphics/primitives/grid3d.c \
graphics/primitives/point2d.c \
graphics/primitives/point3d.c \
graphics/primitives/poly2d.c \
graphics/primitives/poly3d.c \
graphics/objects/hedrons.c \
graphics/objects/prisms.c \
graphics/objects/scene.c \
graphics/objects/texture.c \
input/glxevent.c \
modes/actor_test.c \
modes/diamond.c \
modes/map.c \
modes/sandbox.c \
modes/scene_test.c \
modes/stage.c \
util/veccomp.c \
main.c
main_LDFLAGS = -lX11
12 changes: 12 additions & 0 deletions src/graphics/contexts/glcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,37 @@ extern "C" {
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <signal.h>
#include <math.h>
#include <assert.h>
#include <ctype.h>
#include <time.h>

#ifdef _WIN32
#include "wglcontext.h"
#else
#include "glxcontext.h"
#endif /* _WIN32 */

#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
unsigned short xres;
unsigned short yres;
double current_ratio;
bool isfullscreen;

void drawframe();
void setwindowed(unsigned short w_xres, unsigned short w_yres);
void setfullscreen(void);

#ifndef NDEBUG
static GLenum gl_errno;
#endif /* NDEBUG */

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif /* __GLCONTEXT_H__ */


40 changes: 35 additions & 5 deletions src/graphics/contexts/glxcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void glxinit()
int config_count;
dpy = NULL;
vis = NULL;
isfullscreen = true;

/* open X display */
dpy = XOpenDisplay(NULL);
Expand All @@ -35,9 +34,18 @@ void glxinit()
/* determine default screen */
screen_number = XDefaultScreen(dpy);

/* get resolution */
xres = XDisplayWidth(dpy, screen_number);
yres = XDisplayHeight(dpy, screen_number);
if (isfullscreen) {
/* get resolution */
xres = XDisplayWidth(dpy, screen_number);
yres = XDisplayHeight(dpy, screen_number);
}
else {
xres = 640;
yres = 480;
}

/* set aspect ratio */
current_ratio = (double) xres / (double) yres;

/* retrieve root window */
root = XRootWindow(dpy, screen_number);
Expand Down Expand Up @@ -87,7 +95,8 @@ void glxinit()

/* set input events */
attrs.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask | PointerMotionMask;
attrs.override_redirect = True;

attrs.override_redirect = isfullscreen ? True : False;

/* create window */
win = XCreateWindow(
Expand Down Expand Up @@ -193,6 +202,9 @@ void glxfree(void)
return;
}

/*
* setwindowed - pop out to window of defined resolution
*/
void setwindowed(unsigned short w_xres, unsigned short w_yres)
{
if (isfullscreen) {
Expand Down Expand Up @@ -244,6 +256,9 @@ void setwindowed(unsigned short w_xres, unsigned short w_yres)
return;
}

/*
* setfullscreen - set to fullscreen at current resolution
*/
void setfullscreen(void)
{
if (!isfullscreen) {
Expand Down Expand Up @@ -277,6 +292,13 @@ void setfullscreen(void)
exit(EXIT_FAILURE);
}

/* determine default screen */
screen_number = XDefaultScreen(dpy);

/* get resolution */
xres = XDisplayWidth(dpy, screen_number);
yres = XDisplayHeight(dpy, screen_number);

/* resize window */
XMoveResizeWindow(dpy, win, 0, 0, xres, yres);

Expand All @@ -292,3 +314,11 @@ void setfullscreen(void)

return;
}

/*
* render a frame
*/
void drawframe() {
glXSwapBuffers(dpy, window);
return;
}
29 changes: 22 additions & 7 deletions src/graphics/contexts/wglcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void wglinit(HINSTANCE hInstance, int nShowCmd, WNDPROC wndproc)
MONITORINFO monitor_info;
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
monitor_info.cbSize = sizeof (MONITORINFO);
isfullscreen = true;

/* save these properties for screen switching */
wgl_hInstance = hInstance;
Expand Down Expand Up @@ -64,6 +63,9 @@ void wglinit(HINSTANCE hInstance, int nShowCmd, WNDPROC wndproc)
/* get resolution */
xres = (unsigned short) (monitor_info.rcMonitor.right - monitor_info.rcMonitor.left);
yres = (unsigned short) (monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top);

/* set aspect ratio */
current_ratio = (double) xres / (double) yres;

/* set pixel format attributes */
PIXELFORMATDESCRIPTOR pfd = {
Expand All @@ -89,11 +91,11 @@ void wglinit(HINSTANCE hInstance, int nShowCmd, WNDPROC wndproc)
wnd = CreateWindow(
L"MainWndClass"
,L"OpenGL"
,WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
,(isfullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW) | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
,0
,0
,xres
,yres
,isfullscreen ? xres : DEFAULT_WIDTH
,isfullscreen ? yres : DEFAULT_HEIGHT
,(HWND) NULL
,(HMENU) NULL
,hInstance
Expand Down Expand Up @@ -126,8 +128,7 @@ void wglinit(HINSTANCE hInstance, int nShowCmd, WNDPROC wndproc)
/* create context */
context = wglCreateContext(dc);

/* hide cursor */
ShowCursor(FALSE);
if (isfullscreen) ShowCursor(FALSE); /* hide cursor on fullscreen */

/* associate context to window */
wglMakeCurrent(dc, context);
Expand Down Expand Up @@ -215,6 +216,9 @@ void wglfree(HINSTANCE hInstance)
return;
}

/*
* setwindowed - pop out to window of defined resolution
*/
void setwindowed(unsigned short w_xres, unsigned short w_yres)
{
RECT client_rect;
Expand Down Expand Up @@ -264,6 +268,9 @@ void setwindowed(unsigned short w_xres, unsigned short w_yres)
return;
}

/*
* setfullscreen - set to fullscreen at current resolution
*/
void setfullscreen(void)
{
if (!isfullscreen) {
Expand Down Expand Up @@ -307,4 +314,12 @@ void setfullscreen(void)
}

return;
}
}

/*
* render a frame
*/
void drawframe() {
SwapBuffers(dc);
return;
}
Loading

0 comments on commit ba5e5db

Please sign in to comment.