Broken texturing.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
project(Re3D
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
LANGUAGES CXX C
|
||||
)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
@@ -45,10 +45,9 @@ CPMAddPackage(
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-7.zip
|
||||
)
|
||||
|
||||
# BSD 2-clause license.
|
||||
CPMAddPackage(
|
||||
NAME spng
|
||||
URL https://codeload.github.com/randy408/libspng/zip/refs/tags/v0.7.4
|
||||
NAME SOIL
|
||||
URL https://git.redacted.cc/Redacted/SOIL/archive/v1.0.zip
|
||||
)
|
||||
|
||||
add_library(Re3D SHARED ${SOURCES})
|
||||
@@ -66,9 +65,9 @@ include_directories(
|
||||
${ReWindow_SOURCE_DIR}/include
|
||||
${ReHardwareID_SOURCE_DIR}/include
|
||||
${J3ML_SOURCE_DIR}/include
|
||||
${spng_SOURCE_DIR}/spng
|
||||
${SOIL_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
target_link_libraries(Re3D_Demo PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML spng ${OPENGL_LIBRARIES})
|
||||
target_link_libraries(Re3D_Demo PUBLIC Re3D ReWindowLibrary ReHardwareID J3ML soil ${OPENGL_LIBRARIES})
|
||||
|
||||
|
||||
|
BIN
assets/textures/missing.png
Normal file
BIN
assets/textures/missing.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
assets/textures/red.png
Normal file
BIN
assets/textures/red.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <types/entityList.h>
|
||||
#include <types/vertex.h>
|
||||
|
||||
#include <types/texture.h>
|
||||
#include <types/entity.h>
|
||||
|
||||
// TODO: Move data to Entity / or rename to DataModelEntry
|
||||
@@ -41,9 +41,12 @@ public:
|
||||
class World : public DataModel {
|
||||
private:
|
||||
VertexArray playerBaseGeometry;
|
||||
Texture playerBaseTexture;
|
||||
public:
|
||||
|
||||
std::string name;
|
||||
World() : DataModel() {}
|
||||
//TODO: Store these more elegantly of course.
|
||||
VertexArray getPlayerBaseGeometry();
|
||||
GLuint getPlayerTextureID();
|
||||
};
|
||||
|
12
include/types/texture.h
Normal file
12
include/types/texture.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <string>
|
||||
|
||||
class Texture {
|
||||
private:
|
||||
public:
|
||||
void load(const char* file);
|
||||
GLuint id;
|
||||
};
|
@@ -6,6 +6,7 @@
|
||||
#include <sstream>
|
||||
#include <GL/gl.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <types/texture.h>
|
||||
|
||||
struct Vertex {
|
||||
float x, y, z;
|
||||
|
@@ -18,10 +18,16 @@ int DataModel::getMobyCount() const {
|
||||
|
||||
VertexArray World::getPlayerBaseGeometry() {
|
||||
if (playerBaseGeometry.vertices.empty())
|
||||
playerBaseGeometry.load("assets/models/cone.obj");
|
||||
playerBaseGeometry.load("assets/models/cube.obj");
|
||||
return playerBaseGeometry;
|
||||
}
|
||||
|
||||
GLuint World::getPlayerTextureID() {
|
||||
if (playerBaseTexture.id == 0)
|
||||
playerBaseTexture.load("assets/textures/red.png");
|
||||
return playerBaseTexture.id;
|
||||
}
|
||||
|
||||
void Entity::SetParent(Entity *parent) {
|
||||
// hold a reference to this so it doesn't get collected as we're working with it
|
||||
Entity *oldParent = this->parent;
|
||||
|
@@ -21,7 +21,7 @@ void Player::render() {
|
||||
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
|
||||
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
|
||||
geometry.drawWireframe();
|
||||
geometry.draw();
|
||||
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
|
12
src/types/texture.cpp
Normal file
12
src/types/texture.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <types/texture.h>
|
||||
#include <SOIL/SOIL.h>
|
||||
|
||||
void Texture::load(const char* file) {
|
||||
id = SOIL_load_OGL_texture(file, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
printf("SOIL loading error: '%s'\n", SOIL_last_result());
|
||||
exit(0);
|
||||
}
|
||||
}
|
@@ -46,17 +46,26 @@ void VertexArray::load (const std::string& filename) {
|
||||
}
|
||||
|
||||
//TODO: Render queue
|
||||
|
||||
void VertexArray::draw() {
|
||||
if (!indices.empty()) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, engine->world->getPlayerTextureID());
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (size_t i = 0; i < indices.size(); i += 3) {
|
||||
glTexCoord2f(vertices[indices[i]].u, vertices[indices[i]].v);
|
||||
glVertex3f(vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z);
|
||||
|
||||
glTexCoord2f(vertices[indices[i + 1]].u, vertices[indices[i + 1]].v);
|
||||
glVertex3f(vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z);
|
||||
|
||||
glTexCoord2f(vertices[indices[i + 2]].u, vertices[indices[i + 2]].v);
|
||||
glVertex3f(vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z);
|
||||
}
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
//This only works for *really* simple shapes.
|
||||
//Primarily for the bounding box.
|
||||
if (indices.empty()) {
|
||||
|
Reference in New Issue
Block a user