Skip to main content
Rollback to Revision 1
Source Link
House
  • 73.5k
  • 17
  • 188
  • 276

How to create texture coordinates for a spritesheet with lwjgl, and problems with glBlend

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!

EDIT:

Also, my texture contains alpha, so I enabled blending. The only problem is that with blending on everything I draw is as 50% opacity. here's where I enable blending:

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I just want solid graphics that have alpha where the image file specifies. What am I doing wrong?

How to create texture coordinates for a spritesheet with lwjgl, and problems with glBlend

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!

EDIT:

Also, my texture contains alpha, so I enabled blending. The only problem is that with blending on everything I draw is as 50% opacity. here's where I enable blending:

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I just want solid graphics that have alpha where the image file specifies. What am I doing wrong?

How to create texture coordinates for a spritesheet with lwjgl

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!

added 375 characters in body; edited title
Source Link
Kwauhn
  • 102
  • 8

How to create texture coordinates for a spritesheet with lwjgl, and problems with glBlend

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!

EDIT:

Also, my texture contains alpha, so I enabled blending. The only problem is that with blending on everything I draw is as 50% opacity. here's where I enable blending:

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I just want solid graphics that have alpha where the image file specifies. What am I doing wrong?

How to create texture coordinates for a spritesheet with lwjgl

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!

How to create texture coordinates for a spritesheet with lwjgl, and problems with glBlend

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!

EDIT:

Also, my texture contains alpha, so I enabled blending. The only problem is that with blending on everything I draw is as 50% opacity. here's where I enable blending:

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I just want solid graphics that have alpha where the image file specifies. What am I doing wrong?

Source Link
Kwauhn
  • 102
  • 8

How to create texture coordinates for a spritesheet with lwjgl

Using lwjgl and slick-util I've been trying to use certain pieces of a spritesheet as textures. lwjgl uses glTexCoord2f(); to map coordinates to individual vertices, and the coordinates it takes in are normalized (between 1 and 0), so I've been using this code to make the coordinates only use a small piece of the full Texture:

glTexCoord2f(0 / 128, 0 / 128); glVertex2f(0, 0);
glTexCoord2f(0 / 128, 8 / 128); glVertex2f(0, 32);
glTexCoord2f(8 / 128, 8 / 128); glVertex2f(32, 32);
glTexCoord2f(8 / 128, 0 / 128); glVertex2f(32, 0);

but whenever I used normalized coordinates that are a fraction of the images size I just get a solid square that had 50% alpha.

My question is: what am I doing that's making the texture coordinates screw up? Is there a better way to go about this?

Any help is appreciated, thanks in advance!