zmiany jakies
This commit is contained in:
parent
fc6b24fb3d
commit
06e04c26e9
@ -29,7 +29,7 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#version 400 core
|
#version 400 core
|
||||||
|
|
||||||
in vec3 position;
|
layout(location = 3) in vec3 position;
|
||||||
in vec2 textureCoordinates;
|
layout(location = 4) in vec2 textureCoordinates;
|
||||||
in vec3 normal;
|
layout(location = 5) in vec3 normal;
|
||||||
|
|
||||||
out vec2 pass_textureCoordinates;
|
out vec2 pass_textureCoordinates;
|
||||||
out vec3 surfaceNormal;
|
out vec3 surfaceNormal;
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include "freeglut.h"
|
#include "freeglut.h"
|
||||||
#include "glm.hpp"
|
#include "glm.hpp"
|
||||||
|
|
||||||
const float Terrain::SIZE = 400.f;
|
const float Terrain::SIZE = 100.f;
|
||||||
const int Terrain::VERTEX_COUNT = 128;
|
const int Terrain::VERTEX_COUNT = 64;
|
||||||
const int Terrain::COUNT = Terrain::VERTEX_COUNT * Terrain::VERTEX_COUNT;
|
const int Terrain::COUNT = Terrain::VERTEX_COUNT * Terrain::VERTEX_COUNT;
|
||||||
|
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ RawModel Terrain::generateTerrain() {
|
|||||||
for (int i = 0; i < VERTEX_COUNT; i++) {
|
for (int i = 0; i < VERTEX_COUNT; i++) {
|
||||||
for (int j = 0; j < VERTEX_COUNT; j++) {
|
for (int j = 0; j < VERTEX_COUNT; j++) {
|
||||||
vertices[vertexPointer * 3] = float(j) / float(VERTEX_COUNT - 1) * SIZE;
|
vertices[vertexPointer * 3] = float(j) / float(VERTEX_COUNT - 1) * SIZE;
|
||||||
vertices[vertexPointer * 3 + 1] = 0;
|
vertices[vertexPointer * 3 + 1] = getHeight(j,i);
|
||||||
vertices[vertexPointer * 3 + 2] = float(i) / float(VERTEX_COUNT - 1) * SIZE;
|
vertices[vertexPointer * 3 + 2] = float(i) / float(VERTEX_COUNT - 1) * SIZE;
|
||||||
glm::vec3 normal = calculateNormal(j, i);
|
glm::vec3 normal = calculateNormal(j, i);
|
||||||
normals[vertexPointer * 3] = normal.x;
|
normals[vertexPointer * 3] = normal.x;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include "glew.h"
|
#include "glew.h"
|
||||||
#include "freeglut.h"
|
#include "freeglut.h"
|
||||||
#include "glm.hpp"
|
#include "glm.hpp"
|
||||||
|
#include "iostream"
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
TerrainRenderer::TerrainRenderer(GLuint terrainProgram,
|
TerrainRenderer::TerrainRenderer(GLuint terrainProgram,
|
||||||
glm::mat4 projectionMatrix,
|
glm::mat4 projectionMatrix,
|
||||||
@ -28,10 +30,13 @@ void TerrainRenderer::render() {
|
|||||||
initShader();
|
initShader();
|
||||||
prepareTerrain();
|
prepareTerrain();
|
||||||
glDrawElements(GL_TRIANGLES, terrain.getModel().getVertexCount(), GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, terrain.getModel().getVertexCount(), GL_UNSIGNED_INT, 0);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
glDisableVertexAttribArray(1);
|
||||||
|
glDisableVertexAttribArray(2);
|
||||||
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainRenderer::initShader() {
|
void TerrainRenderer::initShader() {
|
||||||
glUseProgram(terrainProgram);
|
|
||||||
glBindAttribLocation(terrainProgram, 0, "position");
|
glBindAttribLocation(terrainProgram, 0, "position");
|
||||||
glBindAttribLocation(terrainProgram, 1, "textureCoordinates");
|
glBindAttribLocation(terrainProgram, 1, "textureCoordinates");
|
||||||
glBindAttribLocation(terrainProgram, 2, "normal");
|
glBindAttribLocation(terrainProgram, 2, "normal");
|
||||||
@ -42,7 +47,6 @@ void TerrainRenderer::initShader() {
|
|||||||
// glUniform3f(glGetUniformLocation(terrainProgram, "lightColour"), lightColour.x, lightColour.y, lightColour.z);
|
// glUniform3f(glGetUniformLocation(terrainProgram, "lightColour"), lightColour.x, lightColour.y, lightColour.z);
|
||||||
glUniform1f(glGetUniformLocation(terrainProgram, "shineDamper"), shineDamper);
|
glUniform1f(glGetUniformLocation(terrainProgram, "shineDamper"), shineDamper);
|
||||||
glUniform1f(glGetUniformLocation(terrainProgram, "reflectivity"), reflectivity);
|
glUniform1f(glGetUniformLocation(terrainProgram, "reflectivity"), reflectivity);
|
||||||
glUseProgram(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainRenderer::prepareTerrain() {
|
void TerrainRenderer::prepareTerrain() {
|
||||||
@ -51,6 +55,6 @@ void TerrainRenderer::prepareTerrain() {
|
|||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
GLuint texture = terrain.getTexture();
|
||||||
glBindTexture(GL_TEXTURE_2D, terrain.getTexture());
|
Core::SetActiveTexture(texture, "modelTexture", terrainProgram, 0);
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ GLuint bubbleProgram;
|
|||||||
GLuint programTexture;
|
GLuint programTexture;
|
||||||
|
|
||||||
GLuint terrainProgram;
|
GLuint terrainProgram;
|
||||||
|
Terrain terrain;
|
||||||
GLuint textureSubmarine;
|
GLuint textureSubmarine;
|
||||||
GLuint textureBubble;
|
GLuint textureBubble;
|
||||||
GLuint textureFish;
|
GLuint textureFish;
|
||||||
@ -372,6 +372,12 @@ void renderScene()
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
glUseProgram(terrainProgram);
|
||||||
|
glm::mat4 terrainTransformation = glm::translate(glm::vec3(terrain.getX(), 0, terrain.getZ())) * glm::rotate(glm::radians(0.f), glm::vec3(5, 5, 5));
|
||||||
|
TerrainRenderer terrainRenderer(terrainProgram, perspectiveMatrix, terrain, terrainTransformation, cameraMatrix, lightDir, 0.5f, 0.5f);
|
||||||
|
terrainRenderer.render();
|
||||||
|
glUseProgram(0);
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 submarineInitialTransformation = glm::translate(glm::vec3(0, -0.5, -0.4)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
|
glm::mat4 submarineInitialTransformation = glm::translate(glm::vec3(0, -0.5, -0.4)) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.25f));
|
||||||
glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation;
|
glm::mat4 submarineModelMatrix = glm::translate(cameraPos + cameraDir) * glm::mat4_cast(glm::inverse(rotation)) * submarineInitialTransformation;
|
||||||
@ -526,10 +532,8 @@ void init()
|
|||||||
|
|
||||||
textureID = Core::LoadTexture("textures/terrain.png");
|
textureID = Core::LoadTexture("textures/terrain.png");
|
||||||
|
|
||||||
Terrain terrain(0, 0, textureID, heightGenerator);
|
terrain = Terrain(0, 0, textureID, heightGenerator);
|
||||||
glm::mat4 terrainTransformation = glm::translate(glm::vec3(terrain.getX(), 0, terrain.getZ())) * glm::rotate(glm::radians(180.0f), glm::vec3(0, 1, 0));
|
|
||||||
TerrainRenderer terrainRenderer(terrainProgram, perspectiveMatrix, terrain, terrainTransformation, -cameraMatrix, lightDir, 1.f, 0.f);
|
|
||||||
terrainRenderer.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
|
Loading…
Reference in New Issue
Block a user