parent
173ac6e344
commit
ac412093de
@ -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> |
@ -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,7 @@ |
||||
#version 430 |
||||
out vec4 color; |
||||
in vec4 varyingColor; |
||||
void main(void) |
||||
{ |
||||
color=varyingColor; |
||||
} |
Binary file not shown.
@ -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); |
||||
} |
@ -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; |
||||
} |
||||
}; |
@ -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; |
||||
} |
Loading…
Reference in new issue