Many cubes of doom.
This commit is contained in:
parent
173ac6e344
commit
ac412093de
159
Models/Models.vcxproj
Normal file
159
Models/Models.vcxproj
Normal file
@ -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>{6e813500-09f1-40c1-bf2a-e8c4d0de1142}</ProjectGuid>
|
||||
<RootNamespace>Models</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>
|
||||
<None Include="fragShader.glsl" />
|
||||
<None Include="vertShader.glsl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ShaderError.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
38
Models/Models.vcxproj.filters
Normal file
38
Models/Models.vcxproj.filters
Normal file
@ -0,0 +1,38 @@
|
||||
<?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;c++;cppm;ixx;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;h++;hm;inl;inc;ipp;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>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="fragShader.glsl">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="vertShader.glsl">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ShaderError.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
39
Models/ShaderError.h
Normal file
39
Models/ShaderError.h
Normal file
@ -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;
|
||||
}
|
||||
}
|
7
Models/fragShader.glsl
Normal file
7
Models/fragShader.glsl
Normal file
@ -0,0 +1,7 @@
|
||||
#version 430
|
||||
out vec4 color;
|
||||
in vec4 varyingColor;
|
||||
void main(void)
|
||||
{
|
||||
color=varyingColor;
|
||||
}
|
BIN
Models/glew32.dll
Normal file
BIN
Models/glew32.dll
Normal file
Binary file not shown.
111
Models/main.cpp
Normal file
111
Models/main.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <array>
|
||||
|
||||
#define numVAOs 1
|
||||
#define numVBOs 2
|
||||
|
||||
GLuint renderingProgram;
|
||||
GLuint vao[numVAOs];
|
||||
GLuint vbo[numVBOs];
|
||||
|
||||
glm::vec3 camera;
|
||||
glm::vec3 cubeLoc;
|
||||
GLuint vLoc,projLoc;
|
||||
int width, height;
|
||||
float aspect;
|
||||
glm::mat4 pMat, vMat;
|
||||
|
||||
void setupVertices(void) { // 36 vertices, 12 triangles, makes 2x2x2 cube placed at origin
|
||||
float vertexPositions[108] = {
|
||||
-1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f,
|
||||
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f,
|
||||
1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f,
|
||||
1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f,
|
||||
1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||
-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||
-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f,
|
||||
-1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f,
|
||||
-1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f,
|
||||
1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f,
|
||||
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f
|
||||
};
|
||||
glGenVertexArrays(1, vao);
|
||||
glBindVertexArray(vao[0]);
|
||||
glGenBuffers(numVBOs, vbo);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
void init(GLFWwindow* window) {
|
||||
renderingProgram=utils::createShaderProgram("vertShader.glsl","fragShader.glsl");
|
||||
camera={0.0f,0.0f,-200.0f};
|
||||
cubeLoc={0.0f,-2.0f,0.0f};
|
||||
setupVertices();
|
||||
}
|
||||
|
||||
double lastTime=0;
|
||||
GLuint tfLoc;
|
||||
|
||||
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);
|
||||
|
||||
vLoc=glGetUniformLocation(renderingProgram,"v_matrix");
|
||||
projLoc=glGetUniformLocation(renderingProgram,"proj_matrix");
|
||||
|
||||
glfwGetFramebufferSize(window,&width,&height);
|
||||
aspect=(float)width/(float)height;
|
||||
pMat=glm::perspective(utils::degToRad(60),aspect,0.1f,1000.f);
|
||||
|
||||
vMat=glm::translate(glm::mat4(1.0f),glm::vec3{camera.x,camera.y,camera.z});
|
||||
|
||||
glUniformMatrix4fv(vLoc,1,GL_FALSE,glm::value_ptr(vMat));
|
||||
glUniformMatrix4fv(projLoc,1,GL_FALSE,glm::value_ptr(pMat));
|
||||
tfLoc=glGetUniformLocation(renderingProgram,"tf");
|
||||
glUniform1f(tfLoc,(float)currentTime);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER,vbo[0]);
|
||||
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glDrawArraysInstanced(GL_TRIANGLES,0,36,100000);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
if (!glfwInit()) { exit(EXIT_FAILURE); }
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
GLFWwindow* window = glfwCreateWindow(1200, 1200, "Hello Cubes!", 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);
|
||||
}
|
83
Models/utils.h
Normal file
83
Models/utils.h
Normal file
@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <GL/glew.h>
|
||||
#include "ShaderError.h"
|
||||
|
||||
#define PI 3.14159
|
||||
|
||||
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;
|
||||
}
|
||||
inline static float degToRad(float deg){
|
||||
return deg*(PI/180);
|
||||
}
|
||||
|
||||
inline static float radToDeg(float rad){
|
||||
return rad*57.2957795130823208767;
|
||||
}
|
||||
};
|
79
Models/vertShader.glsl
Normal file
79
Models/vertShader.glsl
Normal file
@ -0,0 +1,79 @@
|
||||
#version 430
|
||||
layout (location=0) in vec3 position;
|
||||
uniform mat4 v_matrix;
|
||||
uniform mat4 proj_matrix;
|
||||
uniform float tf;
|
||||
out vec4 varyingColor;
|
||||
|
||||
mat4 buildTranslate(float x, float y, float z);
|
||||
mat4 buildRotateX(float rad);
|
||||
mat4 buildRotateY(float rad);
|
||||
mat4 buildRotateZ(float rad);
|
||||
|
||||
void main(void)
|
||||
{
|
||||
float i = gl_InstanceID + tf;
|
||||
float a = sin(203.0*i/8000.0)*403.0;
|
||||
float b = sin(301.0*i/4001.0)*401.0;
|
||||
float c = sin(400.0*i/6003.0)*405.0;
|
||||
|
||||
mat4 localRotX = buildRotateX(1*i);
|
||||
mat4 localRotY = buildRotateY(1*i);
|
||||
mat4 localRotZ = buildRotateZ(1*i);
|
||||
mat4 localTrans = buildTranslate(a,b,c);
|
||||
|
||||
mat4 newM_matrix = localTrans*localRotX*localRotY*localRotZ;
|
||||
mat4 mv_matrix = v_matrix*newM_matrix;
|
||||
|
||||
gl_Position=proj_matrix*mv_matrix*vec4(position,1.0);
|
||||
varyingColor=vec4(position,1.0)*0.5+vec4(0.5,0.5,0.5,0.5);
|
||||
}
|
||||
// builds and returns a translation matrix
|
||||
mat4 buildTranslate(float x, float y, float z)
|
||||
{
|
||||
mat4 trans = mat4(1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
x, y, z, 1.0 );
|
||||
return trans;
|
||||
}
|
||||
|
||||
// builds and returns a matrix that performs a rotation around the X axis
|
||||
mat4 buildRotateX(float rad)
|
||||
{
|
||||
mat4 xrot = mat4(1.0, 0.0, 0.0, 0.0,
|
||||
0.0, cos(rad), -sin(rad), 0.0,
|
||||
0.0, sin(rad), cos(rad), 0.0,
|
||||
0.0, 0.0, 0.0, 1.0 );
|
||||
return xrot;
|
||||
}
|
||||
|
||||
// builds and returns a matrix that performs a rotation around the Y axis
|
||||
mat4 buildRotateY(float rad)
|
||||
{
|
||||
mat4 yrot = mat4(cos(rad), 0.0, sin(rad), 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
-sin(rad), 0.0, cos(rad), 0.0,
|
||||
0.0, 0.0, 0.0, 1.0 );
|
||||
return yrot;
|
||||
}
|
||||
|
||||
// builds and returns a matrix that performs a rotation around the Z axis
|
||||
mat4 buildRotateZ(float rad)
|
||||
{
|
||||
mat4 zrot = mat4(cos(rad), -sin(rad), 0.0, 0.0,
|
||||
sin(rad), cos(rad), 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0 );
|
||||
return zrot;
|
||||
}
|
||||
|
||||
// builds and returns a scale matrix
|
||||
mat4 buildScale(float x, float y, float z)
|
||||
{
|
||||
mat4 scale = mat4(x, 0.0, 0.0, 0.0,
|
||||
0.0, y, 0.0, 0.0,
|
||||
0.0, 0.0, z, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0 );
|
||||
return scale;
|
||||
}
|
@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGLTemplate", "OpenGLTem
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dot", "Dot\Dot.vcxproj", "{58758496-B3F4-482C-93BA-740C847A58CB}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Models", "Models\Models.vcxproj", "{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -31,6 +33,14 @@ Global
|
||||
{58758496-B3F4-482C-93BA-740C847A58CB}.Release|x64.Build.0 = Release|x64
|
||||
{58758496-B3F4-482C-93BA-740C847A58CB}.Release|x86.ActiveCfg = Release|Win32
|
||||
{58758496-B3F4-482C-93BA-740C847A58CB}.Release|x86.Build.0 = Release|Win32
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Debug|x64.Build.0 = Debug|x64
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Debug|x86.Build.0 = Debug|Win32
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Release|x64.ActiveCfg = Release|x64
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Release|x64.Build.0 = Release|x64
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Release|x86.ActiveCfg = Release|Win32
|
||||
{6E813500-09F1-40C1-BF2A-E8C4D0DE1142}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
x
Reference in New Issue
Block a user