May 02, 2024, 12:58:16 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Noob questions #1

Started by Protected, May 15, 2006, 12:34:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

Just like in C++ you have to be running as an instance of that class in order to call a base class method like that.
Ionic Wind Support Team

Mike Stefanik

A pure virtual method is a method that must be implemented by a derived class; a virtual method (not pure) may be implemented by a derived class (i.e.: overridden); if it's not, then the base class implementation is called.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Protected


Protected

I was playing around with window handling. In the lines example, I changed linewin to inherit from C2DScreen, and changed the window creation command from Create to CreateWindowed. It worked fine. Then I changed it to a CreateFullScreen to see what would happen. Amazingly enough (for me), it created fine, the menu displayed (and worked). However, lines were not drawn. First I thought the full screen window might not be calling OnCreate, so I tried starting the timer in main, but that still didn't work. Are fullscreen windows purely DX? Can't they receive normal window drawing methods (only drawing to the DX buffer)? Or shouldn't windowed DX accept these methods either?

Ionic Wind Support Team

Full screens do inherit from CWindow.  The lines program was meant for an autodrawn GDI window.  You would need to adjust it to use the 2D screen with flipping.  You can use all GDI drawing commands and then flip to show the changes.

Also the C2DSurface object has it's own line drawing methods that work directly with the buffer instead of going through the GDI first.  Much faster.

The only reason you still saw the lines being drawn in the windowed version is you were not flipping, and GDI was still treating it as a normal window.  Autodrawn windows have an internal bitmap that is blitted to the DC of the window.

Paul.



Ionic Wind Support Team

Protected

I know the surface has its own methods, but I'm playing around with the behavior of windows right now...

So doesn't the fullscreen window have that internal GDI bitmap? Or it does but it's never drawn in the window? It surprised me that the menus were there...

Protected

I tried flipping the window. The lines appear, often IN weird colors, and the menus disappear. If I use alt+tab twice, the window goes back to the original status, though - blank with menus.

Ionic Wind Support Team

GDI and DX are two different interfaces.  You have to continually flip to show your changes, just like you did in IB Pro. 

You can use the GDI commands as long as you have them in your main flipping loop.  Autodrawn windows are only for windows, not DirectX. 

You can draw directly on the front buffer, as outlined in the mandelbrot example.

Ionic Wind Support Team

Protected

What's confusing me is the behavior of the menus. I only have to flip once for them to be gone and unusable, but if I go to windows and back, the window is back on its original status. Does flipping cause the class to create some kind of temporary surface layer and paste it on top of everything else?

Ionic Wind Support Team

GDI menus are not compatible with DirectX 7 full screens, never have been.  Windows will draw them on top of your DX surfaces and they will just get overwritten with anything you do in DirectX, you can switch to the GDI surface by using a few tricks, but it will never look the way you expect. 

It is the same thing for controls.  The GDI isn't aware of the DX surface, so it just paints the control on top of the buffers, using the GDI surface.  Attempting to click on a control will fail usually.  Which is why you see all those custom drawn controls and menus in games.

Try this out to see what I mean, you can access the menu by clicking at the top of the screen, but the Windows GDI has no clue it is really a DirectX screen so it immediately gets overwritten:


/*the lines program
displays random lines in direcx forever
For Aurora 1.0 or greater
Compile as a WINDOWS target*/

class linewin : C2DScreen
{
//virtual overrides used by our window
declare OnCreate(),int;
declare OnClose(),int;
declare OnMenuPick(int nID),int;
declare OnSize(int nType,int cx,int cy),int;
declare OnTimer(int nIDEvent),int;
declare OnMenuInit(unsigned int hmenu),int;
//variables used by our window
int l,t,w,h,size,run;
}

linewin::OnCreate(),int
{
CenterWindow();
size = 1;
run = 1;
//draw the lines every 10 millesceonds
StartTimer(10);
return true;
}

linewin::OnClose(),int
{
StopTimer();
run = 0;
return true;
}

linewin::OnMenuPick(int nID),int
{
select( nID )
{
CASE 1:
DrawRect(0,0,w,h,RGB(255,255,255),RGB(255,255,255));
CASE 2:
CASE& 3:
CASE& 4:
SetLineStyle(LSSOLID,nID - 1);
size = nID - 1;
CASE 5:
StopTimer();
run = 0;
}
return true;
}

linewin::OnSize(int nType,int cx,int cy),int
{
rc = GetClientRect();
l = rc.Left;
t = rc.Top;
w = rc.Right - rc.Left;
h = rc.Bottom - rc.Top;
return true;
}

linewin::OnTimer(int nIDEvent),int
{
for( x = 0; x < 10; x++)
{
line( rnd(w),rnd(h),rnd(w),rnd(h),RGB(rnd(255),rnd(255),rnd(255)));
}
return true;
}

linewin::OnMenuInit(unsigned int hmenu),int
{
CMenu m;
m.Attach(hmenu);
m.CheckMenuItem(2,size = 1);
m.CheckMenuItem(3,size = 2);
m.CheckMenuItem(4,size = 3);
m.Detach();
DrawMenuBar();
return false;
}

global sub main()
{
linewin win;
CMenu m;
m.BeginMenu();
m.MenuTitle("&Options");
m.MenuItem("Clear",0,1);
m.BeginPopup("Line Size");
m.MenuItem( "1",0,2 );
m.MenuItem( "2",0,3 );
m.MenuItem( "3",0,4 );
m.EndPopup();
m.MenuItem( "Quit",0,5 );
m.EndMenu();

win.CreateFullScreen(640,480,32);
win.SetMenu(m.Detach());
C2DSurface *front = win.GetFront();
C2DSurface *back = win.GetBack();
//draw directly on the front buffer
win.SetBack(front);
front->Fill(RGB(255,255,255));
do
{
wait(1);
}until win.run = 0 OR GetKeyState(0x1B);
win.SetBack(back);
win.CloseScreen();
return;
}



Now if you switched that to a windowed screen it would do something odd.  Draw on top of all other programs.  When "Windows" is being shown there is only one surface, the front surface.  So you end up drawing on top of other windows.

Conversly a properly set up DirectX program works fine in windowed mode.  Draw to the back buffer, call flip, and DirectX copies the contents of the back buffer to the area occupied by your window with a blit.

Paul.
Ionic Wind Support Team

Protected

Ok, thanks for the example  ;D

Ionic Wind Support Team

Aurora's 2D classes have the same or better functionality that the original IBasic ones.  So if you get stuck on something let me know. They are about 80% completed and are missing the DirectInput classes, since I wanted to add support for my force feedback steering wheel.

Nothing like a fake plastic sterring wheel, vibrating in your hands, to give you the feel of the virtual road ;)
Ionic Wind Support Team