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