Game Development Community

Embed graph in a bitmap control

by Liu Yi · in Torque Game Engine · 08/04/2005 (7:06 pm) · 13 replies

I was trying to use my own created GUI element which provides some graph plotting function .

Ideally I want it to be embedded in a bitmap control, so that the bitmap control provide a border and panel for the plot.

However when I tried to do this, the graph is not plotted properly, only the background is showing and all lines and texts are gone

But when I tested the GUI separately it works perfectly.

anybody could enlighten me? thanks.


Here is what I do
New GuiBitmapCtrl(ProjectilePlotGui) {

   profile = "GuiDefaultProfile";

   horizSizing = "right";

   vertSizing = "bottom";

   position = "0 0";

   extent = "800 600";

   minExtent = "8 8";

   visible = "1";

   helpTag = "0";

 

   new GuiProjectilePlotCtrl(projectileView1) {

     profile = "GuiWindowProfile";

     horizSizing = "left";

     vertSizing = "bottom";

     position = "10 340";

     extent = "250 250";

     minExtent = "8 8";

     visible = "1";

     helTag = "0";

     text = "";

     maxLength = "255";

     resizeWidth = "0";

     resizeHeight = "0";

     canMove = "0";

     canClose = "1";

     canMinimize = "0";

     canMaximize = "0";

     minSize = "50 50";

  };

};

And I use openGL's line drawing function

glBegin(GL_LINE_STRIP);;

glColor3fv(mLineColor);

glVertex2f(....)

glVertex2f(...)

...

glEnd();

to draw the lines

#1
08/04/2005 (8:53 pm)
Can you post your full onRender code for the GuiControl? Please use the [
] [
] tags so that it's more legible. :)
#2
08/04/2005 (11:43 pm)
Here is the onrender code, please take a look
void GuiProjectilePlotCtrl::onRender(Point2I offset, const RectI &updateRect)
{
   if (mProfile->mBorder)
   {
      RectI rect(offset.x, offset.y, mBounds.extent.x, mBounds.extent.y);
      dglDrawRect(rect, mProfile->mBorderColor);
   }

   setUpGtoL(mViewType);              
   glBegin(GL_LINE_STRIP);
   glColor3fv(mLineColor);
   glVertex2f(getPosition().x + mInsetX, 
              getPosition().y + getExtent().y - mInsetY);
   glVertex2f(getPosition().x + getExtent().x - mInsetX, 
              getPosition().y + getExtent().y - mInsetY);
   glVertex2f(getPosition().x + getExtent().x - mInsetX, 
              getPosition().y + mInsetY);
   glEnd();
   glBegin(GL_TRIANGLES);
   glColor3fv(mLineColor);
   glVertex2f(getPosition().x + mInsetX, getPosition().y + getExtent().y - mInsetY - 3);
   glVertex2f(getPosition().x + mInsetX, getPosition().y + getExtent().y - mInsetY + 3);
   glVertex2f(getPosition().x + mInsetX - 8, getPosition().y + getExtent().y - mInsetY); 
   glEnd();
   glBegin(GL_TRIANGLES);
   glColor3fv(mLineColor);
   glVertex2f(getPosition().x + getExtent().x - mInsetX - 3, getPosition().y + mInsetY);
   glVertex2f(getPosition().x + getExtent().x - mInsetX + 3, getPosition().y + mInsetY);
   glVertex2f(getPosition().x + getExtent().x - mInsetX, getPosition().y + mInsetY - 8); 
   glEnd();
   GFont *font = mProfile->mFont;
   Point2I textPoint1((S32)(getPosition().x + mInsetX - 4), (S32)(getPosition().y + getExtent().y - mInsetY + 4));
   Point2I textPoint2((S32)(getPosition().x + getExtent().x - mInsetX + 4),  (S32)(getPosition().y + mInsetY - 4)); 
   if (mViewType == 1)
   {
      dglDrawText(font, textPoint1, "X", mProfile->mFontColors);
      dglDrawText(font, textPoint2, "Y", mProfile->mFontColors);
   }
   if (mViewType == 2)
   {
      dglDrawText(font, textPoint1, "X", mProfile->mFontColors);
      dglDrawText(font, textPoint2, "Z", mProfile->mFontColors);
   }
   if (mViewType == 3)
   {
      dglDrawText(font, textPoint1, "Y", mProfile->mFontColors);
      dglDrawText(font, textPoint2, "Z", mProfile->mFontColors);
   }
}
#3
08/05/2005 (2:24 am)
What is setUpGtoL(mViewType); doing?

Have you looked at the GuiGraphCtrl?

Are you sure you're setting a color, that no texture is active, that blending is turned off?
#4
08/05/2005 (5:12 am)
SetUpGtoL(mViewType) is just a function to convert points in 3D system into ones in 2D system.

"Are you sure you're setting a color, that no texture is active, that blending is turned off?"
Does that mean in order to make glColor3fv(mLineColor) work, i have to set a texture or set a blending or both?
#5
08/05/2005 (11:10 am)
Quote:
SetUpGtoL(mViewType) is just a function to convert points in 3D system into ones in 2D system.

Are you sure that that code is working properly in this case (ie, that you're not trying to draw points that are off the screen)?

If you have a texture or a blend mode set, your line may be drawing transparently, thus not showing up. It's good to make sure they're off if you're not going to be using them.
#6
08/07/2005 (6:18 pm)
I guess SetUpGtoL should be fine since it merely does some coordination calculation.

Thanks, so could it be the problem that, when i put this control above a bitmap control, the underlining texture of the bitmap prevents
the lines to be drawn correctly?
#7
08/07/2005 (6:42 pm)
Children are (or at least, should be) drawn after their parent. You might check to make sure that the parent isn't call drawChildControls at the wrong time (ie, not last thing in onRender).
#8
02/01/2007 (5:21 pm)
I think there is a serious bug with GuiGraphCtrl as of 1.4.2(not sure about later verisions). its parent's position must be 0 0 or it won't plotted correctly, plots will be drawn out of range.
#9
02/01/2007 (7:09 pm)
You have to use the offset to put the drawing in the correct place. 0, 0 is the upper left corner of the screen. If you do not apply the offset then you will always draw relative to the screen. This is not a bug. That is why this is written like this:
RectI rect(offset.x, offset.y, mBounds.extent.x, mBounds.extent.y);
      dglDrawRect(rect, mProfile->mBorderColor);

The first parameters x and y are the location your widget/guiobject appears on screen.
Also, getPosition() and getExtent() are waste calls. All of the same information is available through variables such as offset and mBounds. There a lot of other variables that will give you more info.
#10
02/22/2007 (7:01 pm)
How do I apply the offset in script? something like this?

new GuiControlProfile(GuiGraphProfile:GuiDefaultProfile){
renderOffset="545 30";
};
#11
02/22/2007 (7:18 pm)
No, the "offset" is part of the parameters passed to you in the onRender function. It gives you the 0,0 position of your window so that you can draw within its bounds. The extents come from mBounds.extent.

In script you could get the position of the window. I am not sure if it is "position". You could do a dump() (in script) on the object to get the correct variable.
#12
02/23/2007 (9:39 am)
How do I apply the offset in script? something like this?

new GuiControlProfile(GuiGraphProfile:GuiDefaultProfile){
renderOffset="545 30";
};
#13
02/23/2007 (10:15 am)
I don't have any idea. Do a dump on your object to determine what variables are available in the object. In your original problem with GuiGraphCtrl I assumed you were coding in C++ as this was a C++ related thread. However, if you are doing everything from script then describe your problem in more detail. Right now it does not make sense as all the offset details I thought were handled internally in the objects C++ code. Please post examples of how you are trying to use GuiGraphCtrl.