parent
532483c6f9
commit
49038b9a88
@ -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,155 @@ |
|||||||
|
<?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>{609a0750-8502-4f60-8e54-ad032d6e216b}</ProjectGuid> |
||||||
|
<RootNamespace>TextureMapping</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> |
||||||
|
</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> |
||||||
|
</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> |
||||||
|
</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> |
||||||
|
</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> |
After Width: | Height: | Size: 180 KiB |
@ -0,0 +1,8 @@ |
|||||||
|
#version 430 |
||||||
|
layout (binding=0) uniform sampler2D samp; |
||||||
|
out vec4 color; |
||||||
|
in vec2 uv; |
||||||
|
void main(void) |
||||||
|
{ |
||||||
|
color=texture(samp,uv); |
||||||
|
} |
Binary file not shown.
After Width: | Height: | Size: 185 KiB |
@ -0,0 +1,186 @@ |
|||||||
|
#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> |
||||||
|
#include <stack> |
||||||
|
|
||||||
|
#define numVAOs 1 |
||||||
|
#define numVBOs 4 |
||||||
|
|
||||||
|
GLuint renderingProgram; |
||||||
|
GLuint vao[numVAOs]; |
||||||
|
GLuint vbo[numVBOs]; |
||||||
|
|
||||||
|
glm::vec3 camera; |
||||||
|
GLuint mvLoc,projLoc; |
||||||
|
int width, height; |
||||||
|
float aspect; |
||||||
|
glm::mat4 mMat, pMat, vMat, mvMat; |
||||||
|
std::stack<glm::mat4>transforms; |
||||||
|
|
||||||
|
GLuint pyrTex; |
||||||
|
|
||||||
|
void setupVertices(void) { // 36 vertices, 12 triangles, makes 2x2x2 cube placed at origin
|
||||||
|
float cubePositions[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 |
||||||
|
}; |
||||||
|
float pyramidPositions[54]={ |
||||||
|
-1.0f, -1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, |
||||||
|
1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, |
||||||
|
1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, |
||||||
|
-1.0f, -1.0f, - 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 0.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 |
||||||
|
}; |
||||||
|
float pyrTexCoords[36] = |
||||||
|
{ 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, // top and right faces
|
||||||
|
0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 1.0f, // back and left faces
|
||||||
|
0.0f, 0.0f, 200.0f, 200.0f, 0.0f, 200.0f, 200.0f, 200.0f, 0.0f, 0.0f, 200.0f, 0.0f }; // base triangles
|
||||||
|
glGenVertexArrays(1, vao); |
||||||
|
glBindVertexArray(vao[0]); |
||||||
|
glGenBuffers(numVBOs, vbo); |
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); |
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(cubePositions), cubePositions, GL_STATIC_DRAW); |
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo[2]); |
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(pyramidPositions), pyramidPositions, GL_STATIC_DRAW); |
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo[3]); |
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(pyrTexCoords), pyrTexCoords, GL_STATIC_DRAW); |
||||||
|
} |
||||||
|
|
||||||
|
void setupTextures(){
|
||||||
|
pyrTex=utils::loadTexture("brick1.jpg"); |
||||||
|
glBindTexture(GL_TEXTURE_2D,pyrTex); |
||||||
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); |
||||||
|
glGenerateMipmap(GL_TEXTURE_2D); |
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
||||||
|
} |
||||||
|
|
||||||
|
void init(GLFWwindow* window) { |
||||||
|
renderingProgram=utils::createShaderProgram("vertShader.glsl","fragShader.glsl"); |
||||||
|
camera={0.0f,2.0f,-10.0f}; |
||||||
|
setupVertices(); |
||||||
|
setupTextures(); |
||||||
|
} |
||||||
|
|
||||||
|
double lastTime=0; |
||||||
|
|
||||||
|
void DrawCube(){ |
||||||
|
glUniformMatrix4fv(mvLoc,1,GL_FALSE,glm::value_ptr(mMat)); |
||||||
|
glUniformMatrix4fv(projLoc,1,GL_FALSE,glm::value_ptr(pMat)); |
||||||
|
glBindBuffer(GL_ARRAY_BUFFER,vbo[0]); |
||||||
|
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0); |
||||||
|
glDrawArrays(GL_TRIANGLES,0,36); |
||||||
|
} |
||||||
|
void DrawTexturedSquarePyramid(){ |
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0); |
||||||
|
glBindTexture(GL_TEXTURE_2D,pyrTex); |
||||||
|
|
||||||
|
glUniformMatrix4fv(mvLoc,1,GL_FALSE,glm::value_ptr(mMat)); |
||||||
|
glUniformMatrix4fv(projLoc,1,GL_FALSE,glm::value_ptr(pMat)); |
||||||
|
glBindBuffer(GL_ARRAY_BUFFER,vbo[2]); |
||||||
|
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0); |
||||||
|
glBindBuffer(GL_ARRAY_BUFFER,vbo[3]); |
||||||
|
glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,0,0); |
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES,0,18); |
||||||
|
} |
||||||
|
|
||||||
|
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); |
||||||
|
glEnable(GL_DEPTH_TEST); |
||||||
|
glDepthFunc(GL_LEQUAL); |
||||||
|
glEnableVertexAttribArray(0); |
||||||
|
glEnableVertexAttribArray(1); |
||||||
|
|
||||||
|
mvLoc=glGetUniformLocation(renderingProgram,"mv_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}); |
||||||
|
transforms.push(vMat); |
||||||
|
|
||||||
|
mMat=glm::scale(transforms.top(),{200.f,1.f,200.f}); |
||||||
|
mMat=glm::translate(mMat,{0.f,0.f,0.f}); |
||||||
|
transforms.push(mMat); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(90)*currentTime/100),{0.f,1.f,0.f}); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(12)),{0.f,0.f,1.f}); |
||||||
|
DrawTexturedSquarePyramid(); |
||||||
|
mMat=glm::translate(transforms.top(),{0.f,0.f,0.f}); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(90)*currentTime/100),{0.f,1.f,0.f}); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(192)),{0.f,0.f,1.f}); |
||||||
|
mMat=glm::translate(mMat,{0.f,4.f,0.f}); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(270)),{0.f,1.f,0.f}); |
||||||
|
DrawTexturedSquarePyramid(); |
||||||
|
|
||||||
|
mMat=glm::translate(transforms.top(),{sin(currentTime*0.5)*6,sin(currentTime*0.5)*0.8-1,cos(currentTime*0.5)*6}); |
||||||
|
transforms.push(mMat); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(24)-28),{0,0,1}); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(24)*currentTime+28),{0,1,0}); |
||||||
|
//DrawCube();
|
||||||
|
|
||||||
|
mMat=glm::rotate(transforms.top(),utils::degToRad(90),{1,0,0}); |
||||||
|
mMat=glm::translate(mMat,{sin(currentTime*3)*3,0,cos(currentTime*3)*3}); |
||||||
|
mMat=glm::scale(mMat,{0.3,0.3,0.3}); |
||||||
|
mMat=glm::rotate(mMat,float(-utils::degToRad(220)*currentTime+4),{0,1,0}); |
||||||
|
//DrawCube();
|
||||||
|
|
||||||
|
mMat=glm::rotate(transforms.top(),utils::degToRad(90),{1,1,0}); |
||||||
|
mMat=glm::translate(mMat,{sin(currentTime*3)*3,0,cos(currentTime*3)*3}); |
||||||
|
mMat=glm::scale(mMat,{0.3,0.3,0.3}); |
||||||
|
mMat=glm::rotate(mMat,float(utils::degToRad(120)*currentTime),{0,1,0}); |
||||||
|
//DrawCube();
|
||||||
|
} |
||||||
|
|
||||||
|
int main(void) { |
||||||
|
if (!glfwInit()) { exit(EXIT_FAILURE); } |
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); |
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
||||||
|
GLFWwindow* window = glfwCreateWindow(1920, 1080, "Texture Mapping!", NULL, NULL); |
||||||
|
glfwSetWindowPos(window,1400,180); |
||||||
|
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,94 @@ |
|||||||
|
#pragma once |
||||||
|
#include <string> |
||||||
|
#include <fstream> |
||||||
|
#include <GL/glew.h> |
||||||
|
#include "ShaderError.h" |
||||||
|
#include <SOIL2/SOIL2.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; |
||||||
|
} |
||||||
|
|
||||||
|
inline static GLuint loadTexture(const char*file){ |
||||||
|
GLuint textureID; |
||||||
|
textureID=SOIL_load_OGL_texture(file,SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y); |
||||||
|
if(!textureID){ |
||||||
|
std::cout<<"Could not load texture file "<<file<<std::endl; |
||||||
|
throw; |
||||||
|
} |
||||||
|
return textureID; |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,67 @@ |
|||||||
|
#version 430 |
||||||
|
layout (location=0) in vec3 position; |
||||||
|
layout (location=1) in vec2 texCoords; |
||||||
|
uniform mat4 mv_matrix; |
||||||
|
uniform mat4 proj_matrix; |
||||||
|
out vec4 varyingColor; |
||||||
|
out vec2 uv; |
||||||
|
|
||||||
|
mat4 buildTranslate(float x, float y, float z); |
||||||
|
mat4 buildRotateX(float rad); |
||||||
|
mat4 buildRotateY(float rad); |
||||||
|
mat4 buildRotateZ(float rad); |
||||||
|
|
||||||
|
void main(void) |
||||||
|
{ |
||||||
|
gl_Position=proj_matrix*mv_matrix*vec4(position,1.0); |
||||||
|
uv=texCoords; |
||||||
|
} |
||||||
|
// 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