Crystal Space
Welcome, Guest. Please login or register.
November 18, 2017, 11:01:11 am

Login with username, password and session length
Search:     Advanced search
9081 Posts in 2051 Topics by 80379 Members
Latest Member: Darbeaues9u
* 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 3063 times)
« on: June 03, 2005, 02:55:02 am »


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:


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

// Tell the camera to render into the frame buffer.

// Draw UI if necessary
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.
« 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:


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

// Tell the camera to render 3D data into the frame buffer.

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

// 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.
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.121 seconds with 14 queries.