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 7012313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:14:21+00:00 2026-05-27T22:14:21+00:00

In OpenGL I’m drawing a 2D isometric grid. (picture: https://i.stack.imgur.com/O4jHV.png ). Please don’t mind

  • 0

In OpenGL I’m drawing a 2D isometric grid. (picture: https://i.stack.imgur.com/O4jHV.png). Please don’t mind the sloppy code as a lot of this is just trying things out, I’m trying to get my hands dirty with this stuff before I’ll properly write the tiling part of my actual engine.

Each tile is 76 pixels wide and 38 pixels high. Now I want to texture each of the tiles with a little grass texture that I made. However, that ain’t going to well!

My problem is, the texture keeps looking all messed up. It’s way smaller than it should be (like half the size), and it’s surrounded by white. This is the code I use to apply the texture (which is of 76×38 in size, of course!).

void drawSquare(int x, int y) {
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, texture);
    glBegin(GL_QUADS);
        glTexCoord2i( 38, -19); glVertex2i(x+38, y);
        glTexCoord2i(-38,  19); glVertex2i(x,    y+19);
        glTexCoord2i( 38, -19); glVertex2i(x-38, y);
        glTexCoord2i(-38,  19); glVertex2i(x,    y-19);
    glEnd();
}

This is the part of the code that calculates the X and Y.

for (int y = 1; y < gridY+1; y++) {
    for (int x = 1; x < gridX+1; x++) {
        drawSquare((x-y) * 38 + (SCREEN_SIZE_X/2), (x+y) * 19);
    }
}

I should probably also add, that I put the settings of my ortho like this.

glOrtho(0, SCREEN_SIZE_X, 0, SCREEN_SIZE_Y, -1, 1);

(SCREEN_SIZE_X and SCREEN_SIZE_Y just being 800×600)

Anyone that could help me out here? That’d be greatly appreciated. Perhaps to make it more clear, this is how it looks like right now!

EDIT:
After some help it’s been changed to this.

glBegin(GL_QUADS);
//glColor3f(r, g, b);
glTexCoord2f(0,1); glVertex2i(x+38, y);
glTexCoord2f(1,1); glVertex2i(x,    y+19);
glTexCoord2f(1,0); glVertex2i(x-38, y);
glTexCoord2f(0,0); glVertex2i(x,    y-19);
glEnd();

Result: https://i.stack.imgur.com/JSSXy.png

  • 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-27T22:14:22+00:00Added an answer on May 27, 2026 at 10:14 pm

    Texture coordinates should go from 0 to 1, not from -38 to 19 when using GL_TEXTURE_2D.

    Also, you should use glTexCoord2f() instead.

    Edit:
    This is probably the easiest/best way: just draw the whole texture as a single quad, and enable transparency (blending), just make sure your texture has the corners 100% transparent!

    Note: you can still use glTexCoord2i() since you always use the whole texture. But if you are going to make a texture atlas, then glTexCoord2f() is necessary.

    void drawSquare(int x, int y) {
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBindTexture(GL_TEXTURE_2D, texture);
        glBegin(GL_QUADS);
            glTexCoord2i(0, 0); glVertex2i(x-38, y-19);
            glTexCoord2i(1, 0); glVertex2i(x+38, y-19);
            glTexCoord2i(1, 1); glVertex2i(x+38, y+19);
            glTexCoord2i(0, 1); glVertex2i(x-38, y+19);
        glEnd();
    }
    

    Remember: Texture coordinates zero point (0,0) is bottom left

    Also, dont forget to set the blendmode as:

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    

    Also, make sure you load your texture with the alpha channel, if its still not working, make sure the alpha channel exists in your opengl texture.

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

Sidebar

Related Questions

OpenGL. Let's say I've drawn one image and then the second one using XOR.
In OpenGL I'm trying to rotate a camera around a point, with camera being
Using OpenGL /GLUT how would I detect if two keys, say 'a' and 'j'
In OpenGL, is there a way to use framebuffer data as vertex data without
In my simple OpenGL program I get the following error about exit redefinition: 1>c:\program
I've been using OpenGL extensions on Windows the painful way . Is GLEW the
I have an OpenGL ES game that I am hacking together. One part of
I have an OpenGL RGBA texture and I blit another RGBA texture onto it
I'm using OpenGL ES on a low-resolution, embedded device . I've applied a vertical
I am new to OpenGL. Wondering if there is any good Scenegraph API/framework for

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.