Answer the question
In order to leave comments, you need to log in
TIF texture is not applied to the model?
The .TIF texture is not applied to the model. The model is displayed with a black background, tell me what's the problem?
class SceneRenderer {
private static final int vertexLocation = 0;
private static final int normalLocation = 1;
////
SceneRenderer(ObjModel objModel, BufferedImage image, ByteBuffer textureUtil) throws Exception {
////////////////////
// Загрузка всех шейдеров
...................
/////////////////////////////////////////
// ТУТ ЗАПИСЫВАЮ ВЕРШИНЫ ИЗ МОДЕЛИ OBJ ФАЙЛА В БУФЕР
int vertexBuffer = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, Geometry.objFileObject(objModel).rewind(), GL_STATIC_DRAW);
// ТУТ ЗАПИСЫВАЮ НОРМАЛЬ В БУФЕР
int normalBuffer = glGenBuffers();
....// ТАКИМ ЖЕ ОБРАЗОМ КАК И ВЕРШИНЫ
//ТУТ ЗАПИСЫВАЕМ КООРДИНАТЫ ТЕКСТУРЫ
int textureBuffer = glGenBuffers();
.....// ТАКИМ ЖЕ ОБРАЗОМ КАК И ВЕРШИНЫ
vaoTriangles = glGenVertexArrays();
glBindVertexArray(vaoTriangles);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
glVertexAttribPointer(normalLocation, 3, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, textureBuffer);
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
vaoLines = glGenVertexArrays();
glBindVertexArray(vaoLines);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
pointsBuffer = glGenBuffers();
vaoPoints = glGenVertexArrays();
///ЗДЕСЬ МОЖЕТ БЫТЬ ОШИБКА , ЗАГРУЗКА ТЕКСТУРЫ
idTextures = glGenTextures();
glBindTexture(GL_TEXTURE_2D, idTextures);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture wrapping to 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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.getWidth(), image.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, textureUtil);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, idTextures);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void render() throws Exception {
....///
FloatBuffer vMatrix = BufferUtils.createFloatBuffer(16);
new Matrix4f()
.lookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f).get(vMatrix);
FloatBuffer mMatrix = BufferUtils.createFloatBuffer(16);
new Matrix4f().translate(modelPosition)
.rotateX(modelRotation.x)
.rotateY(modelRotation.y)
.rotateZ(modelRotation.z)
.scale(modelScale)
.get(mMatrix);
glUseProgram(simpleProgram);
glUniformMatrix4fv(glGetUniformLocation(simpleProgram, "P"), false, pMatrix);
glUniformMatrix4fv(glGetUniformLocation(simpleProgram, "V"), false, vMatrix);
lightPosition.get(lightPoint);
glBindBuffer(GL_ARRAY_BUFFER, pointsBuffer);
glBufferData(GL_ARRAY_BUFFER, lightPoint, GL_STATIC_DRAW);
glBindVertexArray(vaoPoints);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(0);
glDrawArrays(GL_POINTS, 0, 1);
glUseProgram(shaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, idTextures);
glUniform1i(glGetUniformLocation(shaderProgram, "ourTexture"), 0);
glBindVertexArray(textures);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "P"), false, pMatrix);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "V"), false, vMatrix);
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "M"), false, mMatrix);
glUniform3f(glGetUniformLocation(shaderProgram, "light_worldspace"), lightPosition.x, lightPosition.y, lightPosition.z);
glBindVertexArray(vaoTriangles);
glEnableVertexAttribArray(vertexLocation);
glEnableVertexAttribArray(normalLocation);
glEnableVertexAttribArray(2);
glDrawArrays(GL_TRIANGLES, 0, objModel.getIdx().size());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question