Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:44:26+00:00 2026-05-30T19:44:26+00:00

I’m having a problem with a simple 2d tile-based engine I’m working on. On

  • 0

I’m having a problem with a simple 2d tile-based engine I’m working on. On my home computer (Windows 7 64bit, jogl 1.1.1) the textures bind properly to the tiles but on my laptop (Windows Vidta 32bit, jogl 1.1.1) they appear broken.

The sprites image is 600×100 (each sprite being 100×100).

Here is the textureManager class that I’m using.

public class TextureManager {

    private static Texture textureAtlas;
    private static Map<String, TextureCoords> locations;
    private static String imageName;

    public TextureManager() {

        locations = new HashMap<String, TextureCoords>();
    }

    public static void loadAtlas(String name) {

        if(textureAtlas != null) {

            if(imageName == name) return;

            textureAtlas.dispose();
        }

        imageName = name;

        try {

            textureAtlas = TextureIO.newTexture(new File("textures/" + name + ".png"), true);
        }
        catch (GLException e) {

            e.printStackTrace();
        }
        catch (IOException e) {

            e.printStackTrace();
        }

        setAtlasLocations();
    }

    private static void setAtlasLocations() {

        locations.put("blank", textureAtlas.getSubImageTexCoords(0, 0, 100, 100));
        locations.put("tree1", textureAtlas.getSubImageTexCoords(100, 0, 200, 100));
        locations.put("tree2", textureAtlas.getSubImageTexCoords(200, 0, 300, 100));
        locations.put("tree3", textureAtlas.getSubImageTexCoords(300, 0, 400, 100));
        locations.put("rock", textureAtlas.getSubImageTexCoords(400, 0, 500, 100));
    }

    public static void bindTexture() {

        textureAtlas.bind();
    }

    public static TextureCoords getCoords(String name) {

        return locations.get(name);
    }
}

This is the rendering code:

    public void draw(GL gl) {

        gl.glEnable(GL.GL_TEXTURE_2D);

        TextureManager.bindTexture();

        int width = map.width();
        int height = map.height();

        float x = InterfaceManager.mapX;
        float y = InterfaceManager.mapY;

        gl.glTranslatef(x, y - height, 0);

        gl.glBegin(GL.GL_QUADS);

        gl.glNormal3f(0.0f, 0.0f, 1.0f);
        gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

        for(int w = 0; w < width; w++) {

            for(int h = 0; h < height; h++) {

                TextureCoords coords = getCoord(map.getTileType(w, h));

                gl.glTexCoord2f(coords.left(), coords.bottom());
                gl.glVertex3i(w, h, 0);
                gl.glTexCoord2f(coords.right(), coords.bottom());
                gl.glVertex3i(w+1, h, 0);
                gl.glTexCoord2f(coords.right(), coords.top());
                gl.glVertex3i(w+1, h+1, 0);
                gl.glTexCoord2f(coords.left(), coords.top());
                gl.glVertex3i(w, h+1, 0);
            }
        }

        gl.glEnd();

        gl.glTranslatef(-x, -y + height, 0);

        gl.glDisable(GL.GL_TEXTURE_2D);
    }

    private TextureCoords getCoord(int tileType) {

        if(tileType == 0) return TextureManager.getCoords("blank");
        else if(tileType == 1) return TextureManager.getCoords("rock");
        else if(tileType == 2) return TextureManager.getCoords("tree1");
        else if(tileType == 3) return TextureManager.getCoords("tree2");
        else if(tileType == 4) return TextureManager.getCoords("tree3");
        else return TextureManager.getCoords("blank");
    }

I know opengl is supposed to be platform independent, and since I’m using the same versions of opengl on both, I’m assuming there’s probably a bug in my code.

Hopefully someone more experienced with it can help me out with this problem. Thanks!

EDIT: Here is a picture of the skewed result.

screwedTexture

The trees along the top and right side is actually supposed to be the rock in the sprite below.

This is the sprite file:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:44:27+00:00Added an answer on May 30, 2026 at 7:44 pm

    The automatically generated mipmaps by OpenGL were causing the problem. Changing the below line to not allow auto mipmapping fixes the problem.

    textureAtlas = TextureIO.newTexture(new File("textures/" + name + ".png"), false);
    

    If anyone would like to comment on how i should create my sprite file to allow auto mipmapping, or if this should even be on, please do 🙂

    With mipmapping off, as i move the character around, some tiles get a black line beneath them. I’ll have to figure out how to make the sprite image mipmap-able.

    EDIT: Make the file square and to the power of 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.