mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
UV data fixed
This commit is contained in:
parent
01a2575f8f
commit
bc89bd0592
@ -41,7 +41,8 @@ std::unique_ptr<Model> LoaderDFF::loadFromMemory(char *data)
|
||||
}
|
||||
|
||||
/** TEX COORDS **/
|
||||
if (geometry.flags & RW::BSGeometry::TexCoords1 || geometry.flags & RW::BSGeometry::TexCoords2) {
|
||||
if ((geometry.flags & RW::BSGeometry::TexCoords1) == RW::BSGeometry::TexCoords1 ||
|
||||
(geometry.flags & RW::BSGeometry::TexCoords2) == RW::BSGeometry::TexCoords1) {
|
||||
for (size_t v = 0; v < geometry.numverts; ++v) {
|
||||
geometryStruct.texcoords.push_back(readStructure<RW::BSGeometryUV>(data, dataI));
|
||||
}
|
||||
@ -110,15 +111,41 @@ std::unique_ptr<Model> LoaderDFF::loadFromMemory(char *data)
|
||||
glGenBuffers(1, &geometryStruct.VBO);
|
||||
glGenBuffers(1, &geometryStruct.EBO);
|
||||
|
||||
size_t buffsize = (geometryStruct.vertices.size() * sizeof(float) * 3)
|
||||
+ (geometryStruct.texcoords.size() * sizeof(float) * 2)
|
||||
+ (geometryStruct.normals.size() * sizeof(float) * 3);
|
||||
|
||||
// Vertices
|
||||
glBindBuffer(GL_ARRAY_BUFFER, geometryStruct.VBO);
|
||||
glBufferData(
|
||||
glBufferData(GL_ARRAY_BUFFER, buffsize, NULL, GL_STATIC_DRAW);
|
||||
|
||||
glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
geometryStruct.vertices.size() * 3 * sizeof(float),
|
||||
&geometryStruct.vertices[0],
|
||||
GL_STATIC_DRAW
|
||||
0,
|
||||
(geometryStruct.vertices.size() * sizeof(float) * 3),
|
||||
&geometryStruct.vertices[0]
|
||||
);
|
||||
|
||||
if(geometryStruct.texcoords.size() > 0)
|
||||
{
|
||||
glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
(geometryStruct.vertices.size() * sizeof(float) * 3),
|
||||
(geometryStruct.texcoords.size() * sizeof(float) * 2),
|
||||
&geometryStruct.texcoords[0]
|
||||
);
|
||||
}
|
||||
|
||||
if(geometryStruct.normals.size() > 0 )
|
||||
{
|
||||
glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
(geometryStruct.vertices.size() * sizeof(float) * 3) + (geometryStruct.texcoords.size() * sizeof(float) * 2),
|
||||
geometryStruct.normals.size() * 3 * sizeof(float),
|
||||
&geometryStruct.normals[0]
|
||||
);
|
||||
}
|
||||
|
||||
// Elements
|
||||
uint16_t indicies[geometryStruct.triangles.size() * 3];
|
||||
size_t i = 0;
|
||||
|
@ -33,9 +33,17 @@ bool TextureLoader::loadFromMemory(char *data)
|
||||
continue;
|
||||
|
||||
auto texNative = rootSection.readStructure<RW::BSTextureNative>();
|
||||
if ( ! (texNative.rasterformat & RW::BSTextureNative::FORMAT_EXT_PAL8))
|
||||
continue;
|
||||
|
||||
if(texNative.platform != 8)
|
||||
{
|
||||
std::cerr << "Unsupported texture platform " << std::dec << texNative.platform << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
GLuint texture = 0;
|
||||
|
||||
if((texNative.rasterformat & RW::BSTextureNative::FORMAT_EXT_PAL8) == RW::BSTextureNative::FORMAT_EXT_PAL8)
|
||||
{
|
||||
auto palette = rootSection.readSubStructure<RW::BSPaletteData>(sizeof(RW::BSTextureNative));
|
||||
auto coldata = rootSection.raw() + sizeof(RW::BSTextureNative) + sizeof(RW::BSPaletteData);
|
||||
|
||||
@ -55,15 +63,55 @@ bool TextureLoader::loadFromMemory(char *data)
|
||||
}
|
||||
}
|
||||
|
||||
GLuint texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
// todo: not completely ignore everything the TXD says.
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGBA,
|
||||
texNative.width, texNative.height, 0,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, fullColor
|
||||
);
|
||||
}
|
||||
else if(
|
||||
texNative.rasterformat == RW::BSTextureNative::FORMAT_1555 ||
|
||||
texNative.rasterformat == RW::BSTextureNative::FORMAT_8888 ||
|
||||
texNative.rasterformat == RW::BSTextureNative::FORMAT_888
|
||||
)
|
||||
{
|
||||
auto coldata = rootSection.raw() + sizeof(RW::BSTextureNative) + sizeof(uint32_t);
|
||||
|
||||
GLenum type, format;
|
||||
switch(texNative.rasterformat)
|
||||
{
|
||||
case RW::BSTextureNative::FORMAT_1555:
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||
break;
|
||||
case RW::BSTextureNative::FORMAT_8888:
|
||||
format = GL_BGRA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case RW::BSTextureNative::FORMAT_888:
|
||||
format = GL_BGR;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
}
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGBA,
|
||||
texNative.width, texNative.height, 0,
|
||||
format, type, coldata
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Unsuported raster format " << std::hex << texNative.rasterformat << std::endl;
|
||||
}
|
||||
|
||||
if(texture != 0)
|
||||
{
|
||||
// todo: not completely ignore everything the TXD says.
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
|
||||
@ -72,6 +120,7 @@ bool TextureLoader::loadFromMemory(char *data)
|
||||
std::string name = std::string(texNative.diffuseName);
|
||||
|
||||
textures[name] = texture;
|
||||
}
|
||||
|
||||
// std::cout << "Loaded texture '" << name << "'" << std::endl;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ void render()
|
||||
glBindBuffer(GL_ARRAY_BUFFER, model->geometries[g].VBO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model->geometries[g].EBO);
|
||||
glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 0, (void*)(model->geometries[g].vertices.size() * sizeof(float) * 3));
|
||||
glEnableVertexAttribArray(posAttrib);
|
||||
glEnableVertexAttribArray(texAttrib);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user