2d graphics

Please tell me how it is correct to render 2d graphic objects, such as sprites or images to do things such menus or console for the game? It must be a way to draw characters (as small sprites) fast. And to draw background fast. glDrawPixels and glBitmap are extremly slow even with 3d accel (as I saw on my Voodoo Rush, this funcs in accel mode works even slower than in generic gdi renderer). I wanna console such as in glDoom! Textures must have sizes of powers of 2 so this is not an option…

I usually draw textured quads (or tri) with alpha mask.
Try to play with blending.
glDraw or CopyPixels are damn slow also on xellerated cards.

Bye, rIO.

I’m working on a little 2D sprite based game in OpenGL and I used textured quads with no problem. I use the Windows concept of imagelist to conserve texture space.

//Pseudo Code
ImageList::Add(fileName, colorMask)
{
LoadImage(file);
ConvertImageToRGBA();
CompareEachPixelToMaskAndSetAlpha();
int size=CalculateTexSize(1+m_imageCount);
if (size>m_currentTexSize)
CreateNewTextureAndCopyOldImages();
CopyImageIntoTexture();
}

ImageList::Draw(index, rect)
{
int x, y, xWidth;
xWidth=m_texSize.cx/m_imageSize.cx;
y=m_imageSize.cy*(index/xWidth);
x=m_imageSize.cx*(index%xWidth);
CRectFloat texRect;

SetCurrentTexture(); //glTexImage2D
texRect.left=x/m_texSize.cx;
texRect.top=(y+m_imageSize.cy)/m_texSize.cy;
texRect.right=(x+m_imageSize.cx)/m_texSize.cx;
texRect.bottom=y/m_texSize.cy;
Selec
glBegin(GLQUADS);
glTexCoord2f(texRect.left, texRect.top);
glVertex2f(rect.left, rect.top);
glTexCoord2f(texRect.left, texRect.bottom);
glVertex2f(rect.left, rect.bottom);
glTexCoord2f(texRect.right,texRect.bottom);
glVertex2f(rect.right, rect.bottom);
glTexCoord2f(texRect.right, texRect.top);
glVertex2f(rect.right, rect.top);
glEnd();
}

[This message has been edited by danoon (edited 10-25-2000).]

[This message has been edited by danoon (edited 10-25-2000).]

You also have the option of using glDrawPixels, and a few of the other bitmap options for dumping raw overlays onto the screen. Including alpha, etc.

Well,

glDrawPixels is slow…

The technique i use is, for pure 2d display, :

  • change the projection matrix with glOrtho(0.0f, width, height, 0.0f, znear, zfar)
  • switch to the modelview matrix
  • display all your 2D sprites…
  • change again the projectuon matrix with gluPerspective so i can display 3D stuff again
  • switch to the modelview matrix again

This should be done only once in your main loop because matrix mode switching may cause performance hit. So all your 2d display functions (draw2DMyScore, draw2DMyHealth, draw2DMyRadar,…) should only pre-strore the data and the above desc. should process them once for all…

hope it will help :slight_smile: