PDA

View Full Version : Wall - Texture render bug



Alphaomega86
04-16-2013, 07:51 AM
Hallo,

I've got a 'simple' bug, when i'm rendering a wall with a texture on it. If i try to render it, there are two small black lines.

Look at that:
1011

I really hope someone can help me!

mobeen
04-16-2013, 08:02 AM
Would you mind sharing with us what you are doing in your code? There could be so many reasons for this result. You may not be considering the pitch of the image data or your texture coordinates are out of range etc. Without sharing with us how you are doing it, I am afraid no one can help you.

Alphaomega86
04-16-2013, 09:42 AM
This is my Java class 'Wall.java':


package org.j3de.rendering.scene;

import java.awt.Color;
import java.util.logging.Logger;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

/**
* A 3D object which renders a simple wall with 4 corners.
*
* @author Daniel
*/
public class Wall extends Mesh {

/**
* Class logger.
*/
private static final Logger LOG = Logger.getLogger(Wall.class.getName());
/**
* Color of the wall.
*/
private Color color = Color.WHITE;
/**
* Texture of the wall.
*/
private Texture texture;
/**
* OpenGL call pointer.
*/
private int glList = -1;

@Override
public void render() {
if (glList == -1) {
if (texture == null) {
genColoredWall();
} else {
genTexturedWall();
}
}
GL11.glTranslatef(position.x, position.y, position.z);
GL11.glRotatef(rotation.x, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(rotation.y, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(rotation.z, 0.0f, 0.0f, 1.0f);
GL11.glScalef(scale.x, scale.y, scale.z);
GL11.glCallList(glList);
}

/**
* Sets the color of the wall. The texture must be null.
*
* @param color Wall color.
*/
public void setColor(Color color) {
this.color = color;
deleteList();
}

/**
* Returns the color of the wall.
*
* @return Wall color.
*/
public Color getColor() {
return color;
}

/**
* Sets the texture of the wall.
*
* @param texture Wall texture.
*/
public void setTexture(Texture texture) {
this.texture = texture;
deleteList();
}

/**
* Returns the texture of the wall.
*
* @return Wall texture.
*/
public Texture getTexture() {
return texture;
}

/**
* Deletes the current display list, and sets the value of the list to the
* default value -1.
*/
private void deleteList() {
GL11.glDeleteLists(glList, 1);
glList = -1;
}

/**
* Generates a simple colored wall.
*/
private void genColoredWall() {
glList = GL11.glGenLists(1);
GL11.glNewList(glList, GL11.GL_COMPILE);
GL11.glBegin(GL11.GL_QUADS);
{
GL11.glColor3f(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f);

GL11.glVertex3f(-0.5f, 0, -0.5f);
GL11.glVertex3f(-0.5f, 0, 0.5f);
GL11.glVertex3f(0.5f, 0, 0.5f);
GL11.glVertex3f(0.5f, 0, -0.5f);
}
GL11.glEnd();
GL11.glEndList();
}

/**
* Generates a simple textured wall.
*/
private void genTexturedWall() {
glList = GL11.glGenLists(1);
GL11.glNewList(glList, GL11.GL_COMPILE);
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
GL11.glBegin(GL11.GL_QUADS);
{
GL11.glTexCoord2f(0, 0);
GL11.glVertex3f(-0.5f, 0, -0.5f);

GL11.glTexCoord2f(0, 1);
GL11.glVertex3f(-0.5f, 0, 0.5f);

GL11.glTexCoord2f(1, 1);
GL11.glVertex3f(0.5f, 0, 0.5f);

GL11.glTexCoord2f(1, 0);
GL11.glVertex3f(0.5f, 0, -0.5f);
}
GL11.glEnd();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}
GL11.glEndList();
}
}

And this is my initialization code: (Here i've shadow mapping init code too, i think, this could be the problem)

/**
* Sets the display up for 3D operations.
*
* @param fov Field of view.
* @param aspect View aspect.
* @param zFar Max view distance.
*/
public static void glInitialize3D(int fov, float aspect, float zFar) {
GluUtilities.fov = fov;
GluUtilities.aspect = aspect;
GluUtilities.zFar = zFar;

GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GluUtilities.setPerspective(fov, 0.001f, zFar, aspect);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_NORMALIZE);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);

GL11.glPolygonOffset(1.1f, 4.0f);

GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, BufferUtilities.asFlippedFloatBuffer(1.0f, 1.0f, 1.0f, 1.0f));
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 16.0f);

GL11.glDepthFunc(GL11.GL_LEQUAL);

//For shadow mapping
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_DEPTH_TEXTURE_MODE, GL11.GL_INTENSITY);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, ARBShadowAmbient.GL_TEXTURE_COMPARE_FAIL_VALUE_ARB , 0.5f);

GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_EYE_LINEAR);
GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_EYE_LINEAR);
GL11.glTexGeni(GL11.GL_R, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_EYE_LINEAR);
GL11.glTexGeni(GL11.GL_Q, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_EYE_LINEAR);

GL11.glCullFace(GL11.GL_BACK);

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}

mobeen
04-16-2013, 07:36 PM
Try doing simple texture mapping first. Once it works, add shadow mapping to it.

Alphaomega86
04-18-2013, 07:55 AM
Try doing simple texture mapping first. Once it works, add shadow mapping to it.
Ok, this was not the problem, i removed all shadow mapping code from my project ... still the same problem, hmm..

EDIT
I tried an even bigger texture 1024x1024 and now it works fine, but if i take the 64x64 texture, i got these strange stripes.
Here is a screenshot of the 1024x1024 textured wall in form of a skybox with lense flare effect:
1012
As you can see, no black stripes.

mobeen
04-18-2013, 08:42 PM
Probably it is due to linear filtering. Try using nearest filtering or better mipmaps to see if that helps.