2D rendering questions

Started by
13 comments, last by napalm21 21 years, 4 months ago
I have 2 questions that I need to be answered? But first, so you know why im asking, it is because I am trying to make a little GUI with OpenGL. 1) Is it at all posible to have a texture that does not have dimensions that are powers of 2. If I have a button that is 15px by 67px, would its texture have to be 16px by 128px ? 2) Is there a way to render directly to a texture instead of rendering to the screen and then copy that over to the texture? Without this I need to go into ortho mode, clear, then update the GUI elements, then clear, then to perspective to render 3D, then back to Ortho again, then flip buffers. But it would be much simpler to just draw the 3d stuff, go to ortho update the GUI textures as needed, then draw them. then flip. Is this posible or not, or is there a better way to do this? The only info on this that I have found so far is a tutorial on nehe, but that doesen''t help me much. Where else should I look? (Don''t say Google!)
Advertisement
Textures must be a power of two (it''s a hardware thing) but there''s no rule that you have to use the entire texture on a primitive.

For instance I implemented Video for Windows which draws frames at 320x240. I copy the image to an OpenGL texture and then when I actually render the frame on a primitive I set the texture coordinates to 0,0 and 320/512.0,240/512.0 so it only grabs the image and not the black background.

I could use that wasted space to store other information if I cared.

As for rendering to a texture, yes it can be done directly, there are tutorials around the web but no, I''ve never done it and don''t really know how it''s done.

There was recently an Image of the Day that rendered the scene once to a texture and then once to the real screen in order to create a very realistic mirror that could be placed anywhere in the scene easily.

Ben


IcarusIndie.com [ The Labyrinth | DevZone | The Wall | Hosting | Tiberian Merchandise | GameShot | Fun With Cutouts ]
Thanks
your best bet is to keep all of your gui widget images in one
texture. use it sorta like a tileset and change up your gltexcoord''s
accordingly

-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

-eldee;another space monkey;[ Forced Evolution Studios ]
To replace [part of] a texture:

void glTexSubImage2D(GLenum target, GLint level, GLint xoffset,
GLint yoffset, GLsizei width, GLsizei height,
GLenum format, GLenum type, const GLvoid *pixels);
Defines a two-dimensional texture image that replaces all or part of a contiguous subregion (in 2D, it''s simply a rectangle) of the current, existing two-dimensional texture image. The target parameter must be set to GL_TEXTURE_2D.
The level, format, and type parameters are similar to the ones used for glTexImage2D(). level is the mipmap level-of-detail number. It is not an error to specify a width or height of zero, but the subimage will have no effect. format and type describe the format and data type of the texture image data. The subimage is also affected by modes set by glPixelStore*() and glPixelTransfer*().
pixels contains the texture data for the subimage. width and height are the dimensions of the subregion that is replacing all or part of the current texture image. xoffset and yoffset specify the texel offset in the x and y directions (with (0, 0) at the lower-left corner of the texture) and specify where to put the subimage within the existing texture array. This region may not include any texels outside the range of the originally defined texture array.
I dont know why but when I get the pixels it just gives me a blank texture of the background color when i send it to textsubimg, is there somthing i am forgeting to do?

glReadPixels(0,0,128,128,GL_RGB,GL_UNSIGNED_BYTE,g_pixelData);
glTexSubImage2D (g_textureid,0,0,0,128,128,GL_RGB,GL_UNSIGNED_BYTE,g_pixelData);

but if I use:

glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,128,128,0);

it works.

Another thing that I noticed is that this is slow!!! And it is actualy faster to just render it every frame because the windows change alot. (this is also due to me having a PII @ 233Mhz)

Is there a better way to do it or am I screwed either way?
The slow thing is reading the pixels, not putting them into the texture.
Anyway, you did it wrong. Do it like this:
glBindTexture(GL_TEXTURE_2D, texture_id);glTexSubImage2D(GL_TEXTURE_2D,0,0,0,256,256,GL_RGBA,GL_UNSIGNED_BYTE,your_buffer); 
It has been my experience that glTexSubImage2D is indeed a slow call.
>>It has been my experience that glTexSubImage2D is indeed a slow call. <<

shouldnt be, my gf2mx can do more than 100 million pixels a second with glTexSubImage2D(..) perhaps youre using it wrongly (or are using something else eg glTexImage2D(..)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
I dont have even a decent computer. My card probly doesent go over one thousand pixels per second. And even if i did, i would not want that much of my resources and processing power to go twards the gui, i want that to be used on the 3d and gameplay. I can''t find any gui tutorials, so I guese im better off just drawing it every frame, it is faster than copying...that pixel copy is rediculously slow. Is there a way to make it go faster? Or read the pixels anotehr way?

This topic is closed to new replies.

Advertisement