PDA

View Full Version : 2d maximum productivity ?



Zoomx
10-04-2008, 11:43 AM
Prompt please as with the OpenGL it is possible to get the maximum productivity in 2d for example video output?

glDrawPixels or there is still any function?

Zengar
10-04-2008, 12:22 PM
Use textures with "2D" polygons (basically, render flat 3d surfaces parallel to the display).

Zoomx
10-04-2008, 12:27 PM
Thanks Zengar.

_NK47
10-07-2008, 08:09 AM
Also disable lighting, depth, stencil, blending ... if you dont need them.

Zoomx
10-12-2008, 05:05 AM
Excuse me for a question I only a few days with OpenGL...
"glBegin (GL_QUADS)" it is a polygon?
How to me on it to put texture? "glTexCoord2f"?

glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();

================================
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;

for i:=0 to 512*512*4 do bitmp[i]:= random(255) ;

glTexImage2D(GL_TEXTURE_2D, 0, GL_UNSIGNED_BYTE, 512, 512,
0, GL_RGB, GL_UNSIGNED_BYTE, @bitmp);

glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);

glTexCoord2f(0,0);
glVertex3f(-10.0, 10.0, 0.0);
glTexCoord2f(0,1);
glVertex3f( 10.0, 10.0, 0.0);
glTexCoord2f(1,1);
glVertex3f( 10.0,-10.0, 0.0);
glTexCoord2f(1,0);
glVertex3f(-10.0,-10.0, 0.0);
glEnd();
================================

I see only one white square without a texture?

_NK47
10-13-2008, 02:50 AM
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,created_texture_id);

k_szczech
10-13-2008, 03:26 AM
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


By default, GL_TEXTURE_MIN_FILTER is set to GL_LINEAR_MIPMAP_LINEAR, therefore your texture needs mipmaps. If you don't specity all of them, then result of using such texture is undefined (usually it doesn't appear, which is what happened in your case).

Since you do not need mipmaps, you should just disable them by setting MIN and MAX filters to GL_LINEAR or GL_NEAREST. When mapping a textured quad to screen at 1:1 ratio, GL_NEAREST is the best choice.
When you need smooth scaling, use GL_LINEAR - will work for smooth zooming and downscaling up to 2 times. More than that will require mipmaps to get good results.

Zoomx
10-13-2008, 06:26 AM
Thanks k_szczech for the help now everything is all right.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

But function:
glTexImage2d(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_BYTE, Data);
takes away too many resources?

_NK47
10-13-2008, 06:29 AM
do not upload texture data each frame. create it once and reuse it with glBindTexture.

GLuint id;
glGenTexture(GL_TEXTURE_2D,&id);
glBindTexture(GL_TEXTURE_2D,id);
glTexImage2D(...);

// per frame:
glBindTexture(GL_TEXTURE_2D,id);
drawQuad();

Zoomx
10-13-2008, 07:00 AM
But if each frame the new picture is necessary to me(for example video)?

ZbuffeR
10-13-2008, 07:08 AM
then use glTexSubImage2d

k_szczech
10-13-2008, 07:14 AM
Yes, if you're displaying a video, then you need to update texture each frame.
Still you can optimize it :)

On application startup create a texture (glGenTextures / glBindTexture / glTexImage2D / glTexParameter).

For each displayed frame you only need to update contents of texture (no need to create it again).
For this use glTexSubImage2D.

The difference is, that glTexImage2D creates new texture and glTexSubImage2D only replaces contents of existing texture and you can use it to quickly replace entire texture image.

Texture format is also important. GL_BGR will probably work faster than GL_RGB.

ZbuffeR
10-13-2008, 07:16 AM
For better upload parallelism, use pixel buffer object extension.