question about textures and rendering them

Started by
10 comments, last by jake_Ghost 19 years, 2 months ago
i am using some blizz UI textures for me UI cause i dont want to make my own, but i have a big problem with them. Sense all textures have to have certain resolutions, there are black spaces around what should be drawn, or this light green color. When i render these textures for my UI, i dont want to see the light green or the excess black around it. How do i do that? thx in advanced jake
Advertisement
Quote:Original post by jake_Ghost
i am using some blizz UI textures for me UI cause i dont want to make my own, but i have a big problem with them. Sense all textures have to have certain resolutions, there are black spaces around what should be drawn, or this light green color. When i render these textures for my UI, i dont want to see the light green or the excess black around it. How do i do that?

thx in advanced jake


You can get around the power-of-two restriction by using the GL_ARB_texture_rectangle or GL_ARB_texture_non_power_of_two extensions. If you don't want to do that you would need to adjust your texture coordinates so that it fits to the part of the texture you need, or I suppose you could set the alpha for the unused part to 0 and alpha test them away, but that's probably not as efficient. The best way would most likely be using one of those extensions.
ok thx ill try that for some of them but for the others i wont be able to. Lets say i have button thats like this...
_______
|/ |
| |
| |
|\ |
-------

lets say the parts to the left of the / and \ are ligh green space that i dont want rendered, how exactly would i find out those small points and either alpha them out or stencil them out. O and how would i get around doing that with rounded textures?
If you don't want to play around with extensions you can just use mipmaps. There is no restriction on POT with them. Just call gluBuild2DMipmaps instead of glTexImage2D. HTH
i use mipmaps but the thing is that the textures have places on them that are black spaces that cannot be taken out because of the shape of it. So how do i not draw those places when rendering them?
Quote:Original post by MARS_999
If you don't want to play around with extensions you can just use mipmaps. There is no restriction on POT with them. Just call gluBuild2DMipmaps instead of glTexImage2D. HTH


Ah yes, that should work, but it would also build all the mipmap levels and for a UI you only need one level since it will most likely not be moving relative to the camera. If you don't mind the wasted memory, which could get pretty large, than that is fine.

As for the circular buttons, you would need to use the alpha "trick" for that. It's commonly called color keying. OpenGL doesn't support it directly so you need to manually set an alpha value of zero for the color you specify to be transparent and then use alpha test to ignore zero alpha.

It's much easier to not bother with the color keying and just use an image format that includes alpha values. TGA and PNG are good ones. TGA is pretty simple to write your own loader but for PNG it's probably better to use an image loading library, many of which have been posted in threads all over these boards.
If I am reading what you are doing correctly you want a texture with lets say the right side is a button but the left side is nothing at all? and you want to get rid of that black space... You need to enable alpha testing and make sure you have a 32bit texture .tga or equivalent no .bmps, .jpgs ect... Then just add in this code..
//you may have to setup your glBlendFunc() to blend your images how you wantglEnable(GL_BLEND);glEnable(GL_ALPHA_TEST);glBindTexture(GL_TEXTURE_2D, texture[texture_index]);//render hereglDisable(GL_ALPHA);glDisable(GL_BLEND);


HTH
well i got it to sort of work, but its not right. I can make the black disappear, but when the texture is over something else, it gets blended with it. How do i stop that from happening so that it will just get rid of the black, but not blend the rest of it.
You don't need blending enabled for simple transparency, only if you want something to look translucent. So you just enable alpha test, set alpha func to >0.0, and make sure the alpha where you don't want the texture to show is 0.0 and the alpha where you do want it to show is greater than 0.0
* do NOT use mipmapping in a HUD
* as Kalidor saiz use alpha testing instead of blending
* create your textures with GL_NEAREST instead of linear
Quote:there are black spaces around what should be drawn, or this light green color. When i render these textures for my UI, i dont want to see the light green or the excess black around it

* as others have said change the texture coords (with nearest + no mipmapping) + u will have no errors

This topic is closed to new replies.

Advertisement