Texturing
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.0 KiB |
@@ -6,6 +6,7 @@
|
||||
#include <sstream>
|
||||
#include <GL/gl.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <types/texture.h>
|
||||
|
||||
struct Vertex {
|
||||
|
@@ -38,6 +38,10 @@ void Render::pre_render() {
|
||||
void Render::render() {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
//TODO: *Always* render the camera first.
|
||||
for (auto& e : engine->world->GetChildren()) {
|
||||
if (e->draw)
|
||||
|
@@ -24,7 +24,7 @@ VertexArray World::getPlayerBaseGeometry() {
|
||||
|
||||
GLuint World::getPlayerTextureID() {
|
||||
if (playerBaseTexture.id == 0)
|
||||
playerBaseTexture.load("assets/textures/red.png");
|
||||
playerBaseTexture.load("assets/textures/missing.png");
|
||||
return playerBaseTexture.id;
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <types/collision/collision.h>
|
||||
void Player::pre_render() {
|
||||
geometry = engine->world->getPlayerBaseGeometry();
|
||||
geometry.scale(0.75f);
|
||||
boundingBox = Collision::calculateBoundingBox(&geometry, angle);
|
||||
//std::cout << "Occluded: " << occluded << std::endl;
|
||||
hVelocity = 2;
|
||||
|
@@ -15,10 +15,11 @@ void VertexArray::scale(GLfloat multiplier) {
|
||||
void VertexArray::load (const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cout << "File not found: " << filename << std::endl;
|
||||
std::cerr << "File not found: " << filename << std::endl;
|
||||
engine->quit();
|
||||
return;
|
||||
}
|
||||
std::vector<LinearAlgebra::Vector3> positions;
|
||||
std::vector<LinearAlgebra::Vector2> uvs;
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
@@ -28,17 +29,30 @@ void VertexArray::load (const std::string& filename) {
|
||||
if (prefix == "v") {
|
||||
float x, y, z;
|
||||
stream >> x >> y >> z;
|
||||
vertices.push_back({x, y, z});
|
||||
positions.push_back(LinearAlgebra::Vector3(x, y, z));
|
||||
} else if (prefix == "vt") {
|
||||
float u, v;
|
||||
stream >> u >> v;
|
||||
vertices.back().u = u;
|
||||
vertices.back().v = v;
|
||||
uvs.push_back(LinearAlgebra::Vector2(u, v));
|
||||
} else if (prefix == "f") {
|
||||
unsigned int index, texCoordIndex;
|
||||
unsigned int vertexIndex[3], texCoordIndex[3];
|
||||
char slash;
|
||||
while (stream >> index >> slash >> texCoordIndex) {
|
||||
indices.push_back(index - 1);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
stream >> vertexIndex[i] >> slash >> texCoordIndex[i];
|
||||
vertexIndex[i]--;
|
||||
texCoordIndex[i]--;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vertex vertex;
|
||||
vertex.x = positions[vertexIndex[i]].x;
|
||||
vertex.y = positions[vertexIndex[i]].y;
|
||||
vertex.z = positions[vertexIndex[i]].z;
|
||||
vertex.u = uvs[texCoordIndex[i]].x;
|
||||
vertex.v = uvs[texCoordIndex[i]].y;
|
||||
|
||||
vertices.push_back(vertex);
|
||||
indices.push_back(static_cast<unsigned int>(indices.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user