Crystal Space
Welcome, Guest. Please login or register.
August 29, 2014, 06:45:05 am

Login with username, password and session length
Search:     Advanced search
9008 Posts in 2043 Topics by 8357 Members
Latest Member: Msyexelcarl03
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Mixing 2D and 3D
« previous next »
Pages: [1] Print
Author Topic: Mixing 2D and 3D  (Read 1993 times)
'ST
Guest
« on: June 03, 2005, 02:55:02 am »

Hello.

I've been using CS to make a prototype for a game project I'm working on.

I've got some 3D stuff down and now I've been attempting to work with making a GUI of my own design, seeing that AWS probably won't meet the needs of my project.

Therefore, I've tried to make use of iGraphics2D functions like Blit and Write to get GUI elements on the screen.

However, I've isolated a crash case to occur whenever I call either of these functions.  The prototype will crash and I've narrowed it to a memory access error (which hasn't really totld me what is at fault).  I've theorized that I'm not putting these calls between relevant BeginDraw and FinishDraw calls, but after playing with this extensively I haven't had success.  Further, I've tried putting these calls both before and after the 3D scene is drawn to the frame buffer (obviously, since the 2D stuff would overlay, I would want it after, but it crashes in either instance).

I am guessing that I am not setting up the drawing right such that the 2D functions can work.  Here's a sample of relevent code:

Code:

// Tell 3D driver we're going to display 3D things.
if (!g3d->BeginDraw (engine->GetBeginDrawFlags () | CSDRAW_3DGRAPHICS))
return;

// Tell the camera to render into the frame buffer.
view->Draw();

// Draw UI if necessary
if(show_gui)
{
ReportError("About to write.");
g2d->Write(font, 200, 100, g2d->FindRGB(255, 255, 255), -1, "This is a GUI");

}


I get the error reported but then nothing is displayed before a crash.  I've tried beginning the draw in 2D as well as telling the iGraphics3D that I'm going to draw in 2D (CSDRAW_GRAPHICS2D) but to no avail.

What is the general way to draw using both the 2D and 3D interfaces in CS during the same frame?

Thanks for the help.
Logged
Anonymous
Guest
« Reply #1 on: June 06, 2005, 10:22:10 pm »

Okay, well, I have finally solved my problem.

After fiddling with various BeginDraw and FinishDraw calls in various places and whatnot, I finally stumbled across something that works.  Strangely, it was in waterdemo.cpp that I found an example of 2D and 3D working together.

What I've found is the following general code structure necessary:

Code:

// Tell 3D driver we're going to display 3D things.
if (!g3d->BeginDraw (engine->GetBeginDrawFlags () | CSDRAW_3DGRAPHICS))
   return;

// Tell the camera to render 3D data into the frame buffer.
view->Draw();


//Tell 3D renderer we're going to display 2D things now
if (!g3d->BeginDraw (CSDRAW_2DGRAPHICS))
   return;

// All 2D drawing calls can go here.


This is the general format that allows such mixing.  One FinishDraw function call closes the frame, so that only need to be called once.  It is normally called in the FinishFrame function of the CS apps.

I hope this will help some people, as I couldn't find straightforwardly an example of what I was simply trying to accomplish.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 4.132 seconds with 14 queries.