parent
d493d60fe5
commit
173ac6e344
@ -0,0 +1,159 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" 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> |
||||
<ProjectConfiguration Include="Debug|x64"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|x64"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
</ItemGroup> |
||||
<PropertyGroup Label="Globals"> |
||||
<VCProjectVersion>16.0</VCProjectVersion> |
||||
<Keyword>Win32Proj</Keyword> |
||||
<ProjectGuid>{58758496-b3f4-482c-93ba-740c847a58cb}</ProjectGuid> |
||||
<RootNamespace>Dot</RootNamespace> |
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>true</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>false</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>true</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>false</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
<ImportGroup Label="ExtensionSettings"> |
||||
</ImportGroup> |
||||
<ImportGroup Label="Shared"> |
||||
</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> |
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<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|x64'"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
</ImportGroup> |
||||
<PropertyGroup Label="UserMacros" /> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\OpenGL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
<AdditionalLibraryDirectories>C:\Users\sigon\Documents\OpenGL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
<AdditionalDependencies>glfw3.lib;glew32.lib;soil2-debug.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\OpenGL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
<AdditionalLibraryDirectories>C:\Users\sigon\Documents\OpenGL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
<AdditionalDependencies>glfw3.lib;glew32.lib;soil2-debug.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\OpenGL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
<AdditionalLibraryDirectories>C:\Users\sigon\Documents\OpenGL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
<AdditionalDependencies>glfw3.lib;glew32.lib;soil2-debug.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\OpenGL\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
<LanguageStandard>stdcpp17</LanguageStandard> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
<AdditionalLibraryDirectories>C:\Users\sigon\Documents\OpenGL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
<AdditionalDependencies>glfw3.lib;glew32.lib;soil2-debug.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemGroup> |
||||
<ClCompile Include="main.cpp" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ClInclude Include="ShaderError.h" /> |
||||
<ClInclude Include="utils.h" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="fragShader.glsl" /> |
||||
<None Include="vertShader.glsl" /> |
||||
</ItemGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
<ImportGroup Label="ExtensionTargets"> |
||||
</ImportGroup> |
||||
</Project> |
@ -0,0 +1,39 @@ |
||||
#pragma once |
||||
#include <GL/glew.h> |
||||
#include <cstdlib> |
||||
#include <iostream> |
||||
|
||||
namespace ErrorCheck{ |
||||
inline void printShaderLog(GLuint shader) { |
||||
int len = 0; |
||||
int chWrittn = 0; |
||||
char *log; |
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); |
||||
if (len > 0) { |
||||
log = (char *)malloc(len); |
||||
glGetShaderInfoLog(shader, len, &chWrittn, log); |
||||
std::cout << "Shader Info Log: " << log << std::endl; |
||||
free(log); |
||||
} } |
||||
inline void printProgramLog(int prog) { |
||||
int len = 0; |
||||
int chWrittn = 0; |
||||
char *log; |
||||
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &len); |
||||
if (len > 0) { |
||||
log = (char *)malloc(len); |
||||
glGetProgramInfoLog(prog, len, &chWrittn, log); |
||||
std::cout << "Program Info Log: " << log << std::endl; |
||||
free(log); |
||||
} } |
||||
inline bool checkOpenGLError() { |
||||
bool foundError = false; |
||||
int glErr = glGetError(); |
||||
while (glErr != GL_NO_ERROR) { |
||||
std::cout << "glError: " << glErr << std::endl; |
||||
foundError = true; |
||||
glErr = glGetError(); |
||||
} |
||||
return foundError; |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
#version 430 |
||||
out vec4 color; |
||||
void main(void) |
||||
{ |
||||
color=vec4( |
||||
(gl_FragCoord.x) / 600.f, |
||||
0.0, |
||||
1-(gl_FragCoord.x) / 600.f, |
||||
1.0 |
||||
); |
||||
} |
Binary file not shown.
@ -0,0 +1,57 @@ |
||||
#include <GL/glew.h> |
||||
#include <GLFW/glfw3.h> |
||||
#include "utils.h" |
||||
#include <algorithm> |
||||
|
||||
#define numVAOs 1 |
||||
|
||||
GLuint renderingProgram; |
||||
GLuint vao[numVAOs]; |
||||
|
||||
void init(GLFWwindow* window) { |
||||
renderingProgram=utils::createShaderProgram("vertShader.glsl","fragShader.glsl"); |
||||
glGenVertexArrays(numVAOs,vao); |
||||
glBindVertexArray(vao[0]); |
||||
} |
||||
|
||||
float size=0; |
||||
float inc=150; |
||||
double lastTime=0; |
||||
|
||||
void display(GLFWwindow* window, double currentTime) { |
||||
double elapsedTime=currentTime-lastTime; |
||||
lastTime=currentTime; |
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT); |
||||
glClearColor(0,0,0.2,1); |
||||
glClear(GL_COLOR_BUFFER_BIT); |
||||
|
||||
glUseProgram(renderingProgram); |
||||
size+=inc*elapsedTime; |
||||
if(size>300||size<1){inc*=-1;size=std::clamp(size,1.f,300.f);} |
||||
glPointSize(size); |
||||
|
||||
glDrawArrays(GL_POINTS,0,1); |
||||
} |
||||
|
||||
int main(void) { |
||||
if (!glfwInit()) { exit(EXIT_FAILURE); } |
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); |
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
||||
GLFWwindow* window = glfwCreateWindow(300, 300, "Expanding Dot", NULL, NULL); |
||||
glfwMakeContextCurrent(window); |
||||
if (glewInit() != GLEW_OK) { exit(EXIT_FAILURE); } |
||||
glfwSwapInterval(1); |
||||
|
||||
init(window); |
||||
|
||||
while (!glfwWindowShouldClose(window)) { |
||||
display(window,glfwGetTime()); |
||||
glfwSwapBuffers(window); |
||||
glfwPollEvents(); |
||||
} |
||||
|
||||
glfwDestroyWindow(window); |
||||
glfwTerminate(); |
||||
exit(EXIT_SUCCESS); |
||||
} |
@ -0,0 +1,74 @@ |
||||
#pragma once |
||||
#include <string> |
||||
#include <fstream> |
||||
#include <GL/glew.h> |
||||
#include "ShaderError.h" |
||||
|
||||
class utils{ |
||||
inline static std::string readShaderSource(const char *filePath){ |
||||
std::string content; |
||||
std::ifstream fileStream(filePath, std::ios::in); |
||||
std::string line = ""; |
||||
if(fileStream.fail()){ |
||||
std::cout<<"Could not open shader "<<filePath<<"!"<<std::endl; |
||||
throw; |
||||
} |
||||
while (fileStream.good()) { |
||||
getline(fileStream, line); |
||||
content.append(line + "\n"); |
||||
} |
||||
fileStream.close(); |
||||
return content; |
||||
} |
||||
inline static void CompileShader(GLuint shader,std::string type){ |
||||
GLint compiled; |
||||
glCompileShader(shader); |
||||
ErrorCheck::checkOpenGLError(); |
||||
glGetShaderiv(shader,GL_COMPILE_STATUS,&compiled); |
||||
if(compiled!=1){ |
||||
std::cout<<type<<" Compilation Failed!"<<std::endl; |
||||
ErrorCheck::printShaderLog(shader); |
||||
throw; |
||||
} |
||||
} |
||||
inline static void CreateShader(GLuint type,std::string shaderName,const char*source,GLuint vfProgram){ |
||||
if(source!=nullptr){ |
||||
GLuint vShader=glCreateShader(type); |
||||
std::string shaderFile=readShaderSource(source); |
||||
const char*vertShaderSrc=shaderFile.c_str(); |
||||
glShaderSource(vShader,1,&vertShaderSrc,NULL); |
||||
CompileShader(vShader,shaderName); |
||||
glAttachShader(vfProgram,vShader); |
||||
} |
||||
}; |
||||
public: |
||||
inline static GLuint createShaderProgram(const char*vertex,const char*fragment){ |
||||
return createShaderProgram(vertex,nullptr,nullptr,nullptr,fragment); |
||||
} |
||||
inline static GLuint createShaderProgram(const char*vertex,const char*geometry,const char*fragment){ |
||||
return createShaderProgram(vertex,nullptr,nullptr,geometry,fragment); |
||||
} |
||||
inline static GLuint createShaderProgram(const char*vertex,const char*tesselationCS,const char*tesselationES,const char*fragment){ |
||||
return createShaderProgram(vertex,tesselationCS,tesselationES,nullptr,fragment); |
||||
} |
||||
inline static GLuint createShaderProgram(const char*vertex,const char*tesselationCS,const char*tesselationES,const char*geometry,const char*fragment){ |
||||
|
||||
GLuint vfProgram=glCreateProgram(); |
||||
|
||||
CreateShader(GL_VERTEX_SHADER,"Vertex",vertex,vfProgram); |
||||
CreateShader(GL_FRAGMENT_SHADER,"Fragment",fragment,vfProgram); |
||||
CreateShader(GL_TESS_CONTROL_SHADER,"Tesselation Control",tesselationCS,vfProgram); |
||||
CreateShader(GL_TESS_EVALUATION_SHADER,"Tesselation Evaluation",tesselationES,vfProgram); |
||||
CreateShader(GL_GEOMETRY_SHADER,"Geometry",geometry,vfProgram); |
||||
|
||||
GLint linked; |
||||
glLinkProgram(vfProgram); |
||||
ErrorCheck::checkOpenGLError(); |
||||
glGetProgramiv(vfProgram,GL_LINK_STATUS,&linked); |
||||
if(linked!=1){ |
||||
std::cout<<"Linking Failed!"<<std::endl; |
||||
ErrorCheck::printProgramLog(vfProgram); |
||||
} |
||||
return vfProgram; |
||||
} |
||||
}; |
@ -0,0 +1,5 @@ |
||||
#version 430 |
||||
void main(void) |
||||
{ |
||||
gl_Position=vec4(0.0,0.0,0.0,1.0); |
||||
} |
Loading…
Reference in new issue