Game Development Community

DglDrawBitmapStretch Problems

by Gordon Marsh · in Torque Game Engine · 07/19/2006 (7:29 am) · 20 replies

I'm currently trying to use dglDrawBitmapStretch to paint a simple bitmap on the screen... In guiShapeNameHud I added the following lines to the OnRender method:

RectI* bubbleArea = new RectI(Point2I((S32)projPnt.x, (S32)projPnt.y), Point2I(128, 64));
dglDrawBitmapStretch(bubblePic, *bubbleArea, GFlip_None);
dglClearBitmapModulation();

(where bubblePic holds a 256x128 picture of a bubble)

This paints a white rectangle in the position that I want, but doesn't paint the bitmap. Any ideas?

I have tried different PNG, GIF and JPG formats and different size pictures. The only odd thing I can see is the GBitmap in bubblePic (which is of type TextureObject) has the following properties which I am not sure are OK or not:

1. pPallette = 0x00000000 (null I assume)

and

2. pBits is always something like "MA1K?/L@0MA1K?/OC3OC3H<,L@0E9)K?/OC3L@0MA1L@0MA1OC3QE5TH8VJ:VJ:RF6WK;TH8RF6UI9\P@[O?XLWK;UI9WK;VJ:YM=XL[O?YM=YM=ZN>XL\P@]........"


Thanks,
TheGords

#1
07/19/2006 (7:39 am)
Just for completeness I am loading the bitmap via the following means:

tempHandle = new TextureHandle("rpg/client/ui/bubblepic1.jpg", BitmapKeepTexture, true);
bubblePic = new TextureObject();
bubblePic = (TextureObject*)*tempHandle;
bubblePic->type = BitmapKeepTexture;

Where tempHandle is a TextureHandle and bubblePic is a TextureObject. Both objects are stored in the guiShapeNameHud and I have checked they have data at the point of rendering (albeit with the funny fields I pointed out above).
#2
07/19/2006 (8:25 am)
Hey gordon -

this may have been covered earlier in the other thread,
but why not just use a stock GuiBitmapCtrl ?
#3
07/19/2006 (9:17 am)
He's doing it to cause "chat bubbles" to appear above the players head. guiShapeNameHud is a very logical place to put this rather than instancing a whole lot of guiBitMapCtrls and trying to track them to the players.
#4
07/19/2006 (9:33 am)
Gotcha.
#5
07/19/2006 (10:40 am)
If you look at the Third Person Crosshair resources on the site, the guy who wrote those used some direct GL calls for drawing the crosshair (though it's funny coz' for that case it was much simpler to use a guiBitmapCtrl). Also I think you can look at how the particles draw for a good example.
#6
07/19/2006 (11:19 am)
Thanks Paul. For those interested, this Crosshair resource http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3533 would appear to have some good 2D drawing code.

I haven't had a go at implementing it, but it looks promising, albeit not using dglDrawBitmapStretch at all!
#7
07/19/2006 (3:31 pm)
Unbelievably, I've just re-implemented this with the gl commands approach to painting a bitmap on the screen (as per the crosshair resource)... and it works in the same way, a white rectangle in the right area of the screen, but with no texture painted!

This leads me to think that the texture is not being loaded properly for some very bizaare reason.

In fact, as I was writing this I added the following code after I loaded the texture:

FileStream * myStream = new FileStream();
myStream->open("rpg/client/ui/BubblePic2.png", FileStream::ReadWrite);
bubblePic->bitmap->writeGIF(*myStream);

and a file is created of zero bytes, which probably indicates that the bitmap is not loading in properly.

I suspect the pPallette and pBits "errors" above are to blame, but I will investigate further...
#8
07/19/2006 (3:34 pm)
Try loading your image onto a stock GuiBitmapCtrl ?

it is a power-of-two in each dimension, right ? eg 128x64 or what-have-you ?
#9
07/19/2006 (3:35 pm)
Quote:(where bubblePic holds a 256x128 picture of a bubble)
#10
07/19/2006 (3:38 pm)
Oops, sorry.
#11
07/19/2006 (4:08 pm)
Hmmm, looks like it's loading fine... I forgot to add myStream->close(); when I was writing the loaded texture to a file. So it now writes out to a file fine.

Back to the drawing board...

Anyone heard of any other image constraints, i.e. no use of transparencies?
#12
07/19/2006 (5:56 pm)
We had a bit of code at one time in guiShapeNameHud that was drawing a big friggin triangle over the head of the selected player.
I think that code may be just commented out, take a look in guiRPGHud and make sure nothing is sitting there already.
#13
07/19/2006 (5:57 pm)
Oh yeah BTW pBits looks like it's not being initialized properly that value just doesn't look healthy to me.
#14
07/20/2006 (5:18 am)
Thanks Dreamer - I couldn't see the code, but I did find some more example code in GuiAdvancedCrossHairHud, which unfortunately produces the same result - a white rectangle.

The pBits thing looks bad, but the code I'm using to load it into the TextureHandle is really straightforward. Once the bitmap is loaded, I can also write it out to another file fine!!

Do you think there is any chance that the bitmap is being painted on the other side of my rectangle so I can't see it?

I must apologise for the quantity of posts on this, but I really am tearing my hair out now :(
#15
07/20/2006 (7:10 am)
Kind of made some progress of sorts, with a basic graphic floating around, but it's not ideal. I have taken the code from the textured-names-above-heads resource as below:

MatrixF ModelView;
Point4F Position;
const Point4F XRotation(1,0,0,0);
const Point4F YRotation(0,1,0,0);
const Point4F ZRotation(0,0,1,0);
F32 LeftTexPos;
F32 RightTexPos;
glEnable ( GL_TEXTURE_2D );
glBindTexture ( GL_TEXTURE_2D, nameTexture.getGLName() );
glEnable ( GL_BLEND );
glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
ColorF nameColor;
nameColor.set(255, 250, 250, 1.0f); // RGB values for the colour
glColor4f(nameColor.red, nameColor.green, nameColor.blue, nameColor.alpha);
glEnable ( GL_ALPHA_TEST );
glEnable ( GL_CULL_FACE );
glAlphaFunc ( GL_GREATER, 0.1f );
glPushMatrix();

// Perform Spherical Billboarding.
MatrixF posMatrix = getRenderTransform();
Point3F pos = posMatrix.getPosition();
pos.z += 2.5;
posMatrix.setPosition(pos);
dglMultMatrix(&posMatrix);
dglGetModelview(&ModelView);
ModelView.setColumn(0, XRotation);
ModelView.setColumn(1, YRotation);
ModelView.setColumn(2, ZRotation);
dglLoadMatrix(&ModelView);

// Change the number it divides by to change the font size
F32 Width = nameTexture.getWidth() / 305.0f;
F32 Height = nameTexture.getHeight() / 153.0f;
LeftTexPos = 0.0f;
RightTexPos = 1.0f - LeftTexPos;

// Draw Billboard.
glBegin(GL_QUADS);

// Draw Top part of billboard.
glTexCoord2f (LeftTexPos,0);
glVertex3f (-Width,0,Height);
glTexCoord2f (RightTexPos,0);
glVertex3f (+Width,0,Height);
glTexCoord2f (RightTexPos,1);
glVertex3f (+Width,0,0);
glTexCoord2f (LeftTexPos,1);
glVertex3f (-Width,0,0);
glEnd();

// Restore our Modelview.
glPopMatrix();
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glDisable ( GL_CULL_FACE );
glDisable ( GL_ALPHA_TEST );
glDisable ( GL_BLEND );
glDisable ( GL_TEXTURE_2D );


However... it ONLY works if I put it into Player::OnRender - if I put it into the GuiRPGHud::OnRender function I'm back to my white rectangle.

I guess I could work with the code in player.cc, but am a bit worried that I'm hacking it and asking for trouble later on...
#16
07/20/2006 (7:28 am)
No you should be fine putting it in Player::OnRender
I recommend drawing the background there, and drawing the text in the shapenamehud
#17
07/22/2006 (8:13 am)
I think I used to get white rectangles when I didn't draw at the right position. Double check your world matrix multiplications/setPositions & drawing positions.
#18
07/22/2006 (3:54 pm)
Thanks for all the tips and advice on this everyone.

I'm still having some minor gripes with implementing this, but when I get it sorted I'll post a list of the steps I've gone through in case anyone else wants to implement speech bubbles in the future.
#19
07/28/2006 (3:27 pm)
OK, just to wrap this up, if you're looking at doing speech bubbles, you'll need to do the following:

1. Add a variable to player.cc to hold your text

2. Update the text to all clients by updating it on the server (adapting a resource such as http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2698 should get you most of the way there!)

3. Add a speech bubble graphic (adapting the bitmap display code in a resource such as http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9805 should help here).

4. Draw the text above each of the players heads by adapting guiShapeNameHud.

NB doing this gets you 99% the way there, but I'm still having the problem of text floating around off-centre of the bubble graphic... but this is a challenge I am yet to solve!

Thanks, Gords
#20
09/25/2006 (10:54 am)
Can we get some screen shots and also a resource for this.. Its hard to track in this forum and across two forum threads.