Jump to content
  • Advertisement
Sign in to follow this  
szalejot

OpenGL No textures problem

This topic is 2883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new to OpenGL.
I want to have textures, but I think I'm doing something wrong.

My initiation

public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_CULL_FACE);
gl.setSwapInterval(1);
drawable.addKeyListener(this);
drawable.addKeyListener(thread);

gl.glEnable(GL.GL_NORMALIZE);
gl.glEnable(GL.GL_COLOR_MATERIAL);

loadTextures();
}



Loading texture:

private void loadTextures(){
try{
InputStream stream = getClass().getResourceAsStream("bricks.png");
TextureData data = TextureIO.newTextureData(stream, false, "png");
wallTexture = TextureIO.newTexture(data);
}
catch (IOException ex){
ex.printStackTrace();
System.exit(1);
}
}



and drawing the wall (code for one, others almost the same)

private void addWalls(GL gl, float x, float z, int dir){
gl.glPushMatrix();
gl.glBegin(GL.GL_QUADS);
wallTexture.enable();
wallTexture.bind();
gl.glNormal3f(-1.0f, 0.0f, 0.0f);
gl.glTexCoord2f(0, 0);
gl.glVertex3f(x, 0.0f, z+1);
gl.glTexCoord2f(1, 0);
gl.glVertex3f(x, 1.0f, z+1);
gl.glTexCoord2f(1, 1);
gl.glVertex3f(x, 1.0f, z);
gl.glTexCoord2f(0, 1);
gl.glVertex3f(x, 0.0f, z);
(...)//other walls
wallTexture.disable();
gl.glEnd();
gl.glPopMatrix();
}



wallTexture is opengl.util.texture.Texture
When I run it walls aren't textured, they are just white.
What I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
I guess this is OpenTK (not really familiar with it)? Since this looks like 'old' OpenGL, have you enabled GL_TEXTURE_2D?

By the way, you can deleted the duplicate threads that have no replies by clicking "edit post" and checking "delete".

Share this post


Link to post
Share on other sites
It looks like java. I guess you need to setup the texture object parameters.

BufferedImage image = ImageIO.read(new File(fileName));
texture = TextureIO.newTexture(image, false);
texture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
texture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);

and also
http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Texture
http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!