It's a bit late, but I've been trying to work on this for a little while with no luck so far - so here we go. I'd like to put a black border around a texture I've loaded. My black border is nothing special - just 1 black pixel wide to show the texture has an edge to it. I thought I might do this via use of glTexSubImage2D but I'm not sure I'm heading down the right direction with that - anyway, as you'll see below - for my purposes, it is much the same as glTexImage2D. I thought if I had an existing texture of, say, 64 x 64 pixels and wanted to write a black border around it, I could use another image to lay over the top of it and give all the pixels in the middle a transparent alpha value - that didn't work, so I tried to turn on blending, but that didn't work anywhere close to what I expected. The code I have so far is below... it will run pretty simply I think - just press 1 to overlay the border image onto the existing image, and 2 to return to the original image... I would like to see my border and the original image sitting inside it. I wonder how that is possible? Can I use glDrawPixels to just draw simple rectangles for each of the four lines I want to draw... or should I have another border texture image, say an alpha TGA, that I load and overlay on top of the texture I am showing?
If there's an easy way to get this simple black border - and hopefully be able to remove it (but that is secondary I guess) it would be good to understand.
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
glTexSubImage can be used like glTexImage but you don't put an internal format and you had an offset. So you must shrink you image and put them into an empty texture. The texture should be filled with your border color and the alphavalue. I dosn't understood your code right and at this moment im still a bit sleepy.
Or you choose the easiest way to create an border. Since OpenGL 1.3 there are the possibility to clamp to an border. Following steps you have to do. For the wrap modes you must set GL_CLAMP_TO_BORDER. Set an bordercolor with glTexParameterfv. And last but not least manipulate your texturecoordinates so that clamping will be used.
This should "create" and border around the image without changing anything imagedata. You also can scale and transform the texture matrix so you don't have to change all the coordinates. But the parameters must be set to every texture.
And please notice that the texture wont be drawn 1:1. So if you draws the images acurate 1 texel to 1 pixel you must expand the quad by 1 pixel.
If this isn't looks nice enough it's may better you are creating an extra bordertexture and draw this over every image.
I tried setting border from 0 to 1 in the glTexImage2D calls as that looked dead easy - but all I got then was a white square - could that be because I created my texture, rather than loaded it? I would suspect not. Guess, for me, it's not going to be as easy as that. I'll check out the GL_CLAMP_TO_BORDER next... see where I get with that.
So... using glDrawPixels onto the texture isn't a good idea?
Registriert: Do Dez 05, 2002 10:35 Beiträge: 4234 Wohnort: Dortmund
I don't know why but i have tried the border property sometimes but i don't get it to work. They only switch my graphicscard into the software mode. So it's be quite "an bit" slow.
glDrawPixels only draws to the framebuffer. So you had to read it back from framebuffer to the texture. But i think this isn't really god.
An other way is to create the texture normally with glTexImage and "draws" the border with glSubTexImage. You only create an 1D array which contain your colors. The size of the width should be enough. And then you call glSubTexImage and overdraws the first line. Simple set position to (0, 0), width = width and height = 1. If you draws these array at position (0, 0) with width = 1 and height = height opengl use the same array downwards. So you are able to draws single lines. With 4 calls you have your border.
But you overwrite some of the image data and you can't control the size of the Border. If the texture has an size of 128 the border is 4 times larger than an texture with size of 512.
But I need to ask one of those probably simple questions again... assuming I don't (and I don't) always know the size of my image files on disk - sometimes they might be 256x256 pixels - often they are 300x300... sometimes they're not even square... but I know that OpenGL will them into PoT textures and they'll be square enough - how do I know how large to make my border?
I tested loading up some of my Artist Images - these are all 426x104 and to successfully put a black border around that texture I had to code for 512x128 - that's fine - it makes sense to me. So, my next question is about a square Album cover - when the files could be either 200x200, 256x256, 300x300 or 512x512 I know that OpenGL will make them either 256x256 or 512x512 - but how do I know which one to code for? Is there a test I can do of a texture to, say, find out its width and height in OpenGL?
I tried loading up a 200x180 image file... in OpenGL I'm guessing that gets scaled to PoT 256x256 and my BorderTexture procedure puts nothing on there because I am currently sending 512 and 512 into the Width and Height parameters. So - is there an easy way to figure out what PoT size my textures are?
Great, thanks! This seems to work for all image sizes I have tested... 256x256, 512x512, 512x128 and, of course, the images on disk that are a variety of NPoT sizes - which OpenGL is automatically scaling to PoT textures for me. I'm not sure if it's the most efficient way of doing things, but it works and that's good enough for me right now.
Mitglieder in diesem Forum: 0 Mitglieder und 15 Gäste
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.