Bootstrapped OpenGL
This commit is contained in:
@@ -6,19 +6,13 @@ EndProject
|
|||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Win32 = Debug|Win32
|
Debug|Win32 = Debug|Win32
|
||||||
MinSizeRel|Win32 = MinSizeRel|Win32
|
|
||||||
Release|Win32 = Release|Win32
|
Release|Win32 = Release|Win32
|
||||||
RelWithDebInfo|Win32 = RelWithDebInfo|Win32
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.ActiveCfg = Debug|Win32
|
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.Build.0 = Debug|Win32
|
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.MinSizeRel|Win32.ActiveCfg = Release|Win32
|
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.MinSizeRel|Win32.Build.0 = Release|Win32
|
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.ActiveCfg = Release|Win32
|
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.Build.0 = Release|Win32
|
{FE405CFA-8FCE-4867-92CF-797E73B36482}.Release|Win32.Build.0 = Release|Win32
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32
|
|
||||||
{FE405CFA-8FCE-4867-92CF-797E73B36482}.RelWithDebInfo|Win32.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -39,25 +39,28 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<IncludePath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
<IncludePath>$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath)</IncludePath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<LibraryPath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(SolutionDir)\Libraries\glew-1.10.0\lib\Debug\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Debug;$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<IncludePath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath)</IncludePath>
|
<IncludePath>$(SolutionDir)\Libraries;$(SolutionDir)\Libraries\glew-1.10.0\include;$(SolutionDir)\Libraries\glfw-3.0.4\include;$(SolutionDir)\Libraries\glm-0.9.5.2;$(IncludePath)</IncludePath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<LibraryPath>C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(SolutionDir)\Libraries\glew-1.10.0\lib\Release\Win32;$(SolutionDir)\Libraries\glfw-3.0.4\lib\Release;$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>GLEW_STATIC;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32sd.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -66,16 +69,23 @@
|
|||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>GLEW_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="logging.h" />
|
||||||
|
<ClInclude Include="glerror.h" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@@ -19,4 +19,12 @@
|
|||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="glerror.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="logging.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef _GLERROR_H
|
||||||
|
#define _GLERROR_H
|
||||||
|
|
||||||
|
#define GLFW_INCLUDE_GLU
|
||||||
|
#include <GLFW\glfw3.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
inline bool _GLERROR(char* info, char* file, char* func, unsigned int line)
|
||||||
|
{
|
||||||
|
GLenum error = glGetError();
|
||||||
|
if (error != GL_NO_ERROR)
|
||||||
|
{
|
||||||
|
_LOG(LOG_LEVEL_ERROR, file, func, line, "GL Error: %s %i %s", info, error, gluErrorString(error));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GLERROR(function) \
|
||||||
|
_GLERROR(function, __BASE_FILE__, __func__, __LINE__)
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#ifndef DEBUG_H
|
||||||
|
#define DEBUG_H
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// http://stackoverflow.com/a/2282433
|
||||||
|
#define __func__ __FUNCTION__
|
||||||
|
// http://stackoverflow.com/a/8488201
|
||||||
|
#define __BASE_FILE__ \
|
||||||
|
(strrchr(__FILE__, '/') \
|
||||||
|
? strrchr(__FILE__, '/') + 1 \
|
||||||
|
: (strrchr(__FILE__, '\\') \
|
||||||
|
? strrchr(__FILE__, '\\') + 1 \
|
||||||
|
: __FILE__))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
enum _LOG_LEVEL
|
||||||
|
{
|
||||||
|
LOG_LEVEL_ERROR,
|
||||||
|
LOG_LEVEL_WARNING,
|
||||||
|
LOG_LEVEL_INFO,
|
||||||
|
LOG_LEVEL_DEBUG
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
|
||||||
|
#else
|
||||||
|
static _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const static char* _LOG_LEVEL_PREFIX[] =
|
||||||
|
{
|
||||||
|
"E: ",
|
||||||
|
"W: ",
|
||||||
|
"",
|
||||||
|
"D: "
|
||||||
|
};
|
||||||
|
|
||||||
|
static void _LOG(_LOG_LEVEL logLevel, char* file, char* func, unsigned int line, const char* format, ...)
|
||||||
|
{
|
||||||
|
if (logLevel > LOG_LEVEL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char message[512];
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vsnprintf(message, 512, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (logLevel == LOG_LEVEL_ERROR)
|
||||||
|
{
|
||||||
|
std::cerr << file << ":" << line << " " << func << std::endl;
|
||||||
|
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LOG(logLevel, format, ...) \
|
||||||
|
_LOG(logLevel, __BASE_FILE__, __func__, __LINE__, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define LOG_ERROR(format, ...) \
|
||||||
|
LOG(LOG_LEVEL_ERROR, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define LOG_WARNING(format, ...) \
|
||||||
|
LOG(LOG_LEVEL_WARNING, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define LOG_INFO(format, ...) \
|
||||||
|
LOG(LOG_LEVEL_INFO, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define LOG_DEBUG(format, ...) \
|
||||||
|
LOG(LOG_LEVEL_DEBUG, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,60 @@
|
|||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#define GLFW_INCLUDE_GLU
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <glext.h>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
#include "glerror.h"
|
||||||
|
|
||||||
|
GLFWwindow* window;
|
||||||
|
GLint glVersion[2];
|
||||||
|
GLchar* glVendor;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
// Initialize GLFW
|
||||||
|
if (!glfwInit())
|
||||||
|
{
|
||||||
|
LOG_ERROR("GLFW: Initialization failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a window
|
||||||
|
window = glfwCreateWindow(1280, 720, "OpenGL", nullptr, nullptr);
|
||||||
|
if (!window)
|
||||||
|
{
|
||||||
|
LOG_ERROR("GLFW: Failed to create window");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// GL version info
|
||||||
|
glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]);
|
||||||
|
glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
|
||||||
|
glVendor = (GLchar*)glGetString(GL_VENDOR);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << glVendor << " OpenGL " << glVersion[0] << "." << glVersion[1];
|
||||||
|
#ifdef DEBUG
|
||||||
|
ss << " DEBUG";
|
||||||
|
#endif
|
||||||
|
LOG_INFO(ss.str().c_str());
|
||||||
|
glfwSetWindowTitle(window, ss.str().c_str());
|
||||||
|
|
||||||
|
// Initialize GLEW
|
||||||
|
if (glewInit() != GLEW_OK)
|
||||||
|
{
|
||||||
|
LOG_ERROR("GLEW: Initialization failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
while (!glfwWindowShouldClose(window))
|
||||||
|
{
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user