PDA

View Full Version : Some models do not rendering correctly



GLGangster
12-16-2014, 05:32 PM
This as been doing my head in.

This is what it looks like.

1552


The two triangles should be boxs like the one on the left.

In fact their the same texuredModel instance.

I've try different models and different textures and it seems always the first one rendered works.

I would post code but I have no idea where the problem lies.

All entity at the moment use the same shader.

Thanks for any help people of OpenGL!

GClements
12-16-2014, 10:56 PM
I would post code but I have no idea where the problem lies.

Without code, we have even less idea.

It's rare that a problem can be diagnosed from a screenshot alone.

GLGangster
12-17-2014, 04:19 PM
Here is my renderer class.


package renderEngine;

import models.RawModel;
import models.TexturedModel;




import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.util.vector.Matrix4f;


import enities.Entity;

import room.TRoom;

import shaders.TerrainShader;
import textures.ModelTexture;
import toolBox.Maths;

public class RoomRenderer {


TerrainShader shader;


public RoomRenderer(TerrainShader shader,Matrix4f projectionMatrix){
this.shader=shader;

this.shader.start();
this.shader.loadProjectionMatrix(projectionMatrix) ;
this.shader.stop();
}




public void render(TRoom r){
TexturedModel floor =r.getFloor().getModel();
prepareTextureModel(floor);
prepareInstance(r.getFloor());
GL11.glDrawElements(GL11.GL_TRIANGLES, floor.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0);
unbindTextureModel();

TexturedModel pl =r.getItems().get(0).getModel();
prepareTextureModel(pl);
prepareInstance(r.getItems().get(0));
GL11.glDrawElements(GL11.GL_TRIANGLES, pl.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0);
unbindTextureModel();


TexturedModel model =r.getWall();
prepareTextureModel(model);
for(Entity e: r.getWalls()){
prepareInstance(e);
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0);


}
unbindTextureModel();




for(Entity e: r.getItems()){
prepareTextureModel(e.getModel());
prepareInstance(e);

GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0);

unbindTextureModel();
}



}

private void prepareTextureModel(TexturedModel texturedmodel){
RawModel model = texturedmodel.getRawModel();
GL30.glBindVertexArray(model.getVaoId());
GL20.glEnableVertexAttribArray(0); // Whenever you add a Attr remender to enable and disable
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);

shader.loadTextureRepeat(texturedmodel.getTextureR epeat());
ModelTexture texture = texturedmodel.getTexture();
if(texture.isHasTransparency()){
MasterRenderer.disableCulling();
}


shader.loadShineVariables(texture.getShineDamper() , texture.getReflectivity());

GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturedmodel.getTexture().getID());

}

private void unbindTextureModel(){
MasterRenderer.enableCulling();
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(2);

GL30.glBindVertexArray(0);
}

private void prepareInstance(Entity entity){
Matrix4f transformtionMatrix = Maths.createTransformationMartix(entity.getPositio n(),entity.getRotX()
, entity.getRotY(), entity.getRotZ(), entity.getXScale(),entity.getYScale(),entity.getZS cale());

shader.loadTextureRepeat(entity.getModel().getText ureRepeat());
shader.loadTransformatMatrix(transformtionMatrix);

}








}




It is called why a master render class that was design to spilt up the terrain and no-terrain into deference shaders. But in trying to find the problem I made it only use the terrain shader. I did this because the terrain was being rendered fine, and I could see if the other shader was the souse of the problem. But Even with the terrain shader it still does't work.

If more code is needed I will supple.

GLGangster
12-18-2014, 06:36 PM
I have solved the issue.

The last call to drawElement in the code render method.


GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0)

Should be


GL11.glDrawElements(GL11.GL_TRIANGLES, e.getModel().getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT,0)