Page 1 of 2

2d bmps BEHIND 3D render? Did I find something NOT POSSIBLE?

Posted: Fri Jul 27, 2007 12:48 am
by vrman3d
I've been trying to figure this out for a while, tried TONS of ideas, and searched endless threads to no avail.... Fred, anyone? Someone must have done this, it seems so pedestrian! I can't imagine I found something NOT POSSIBLE to do with PB! =)

Here's the deal:
I need to display 2D images BEHIND the 3D render (in other words BEFORE the 3D). Should I give up now? Is it not at all possible with the current Ogre3D PB implementation?

Please Fred let me know if it's possible to display 2D bmps BEHIND the 3D rendered world. (Kind of the opposite of HUD graphics since it's rendered, err Blt'd first....)

And I can't use BILLBOARDS since I can't use 3d world units/coords and I don't want texture filtering, etc. For what I'm doing I need pixel perfect positioning of (clipped) bmps as the window background. So I'm hoping for some trick to display (at least one) image essentially as if it were the 'Background Image' for the camera.

Should I just give up now or is there a way? Should I go back to DBPro, hehheh I hope not!

Thanks for any help, and best regards,
-=Fred C.=-
(aka VRMan)

Posted: Fri Jul 27, 2007 8:48 am
by Num3
You need a skybox / skydome :P

Posted: Fri Jul 27, 2007 10:04 am
by Kaeru Gaman
yap.
since the idea itself is really uncommon, maybe you are really talking about a skybox/dome.

if you really want something different, try the following:
redirect the output-channel of the 3D into a sprite/image,
and make sure you have a plan (e.g. black) background
in your render output.
then output on the screen in this order:
- your desired background
- your rendersprite
- your foreground.

thing is:
if you want to have the rendering as a 2D-Layer, you must make it a 2D-Object first.
redirecting render output to a sprite will do this.

Nope definitely not a skydome, but thanks for trying =)

Posted: Fri Jul 27, 2007 10:04 am
by vrman3d
@Num3:
Nope definitely not a skydome, but thanks for trying. =)

Read carefully what I was asking about here:
"....I can't use BILLBOARDS since I can't use 3d world units/coords <(I need exact SCREEN/WINDOW coords)> and I don't want texture filtering, etc. For what I'm doing I need pixel perfect positioning of (clipped) bmps as the window background."

So skyboxes won't work, neither will skyspheres, nor skydomes, nor billboards (they almost do...). They won't work for what I need because I need (for reasons I don't really want to reveal *yet*, sorry =) pixel perfect positioning like I said, and it will include text (small) in the bmp bg image, so anything with trilinear/bilinear texture filtering or even mipmapping will screw it up.

Although skyboxes do indeed put bitmaps behind the 3d render, they also severly warp and stretch the texture (and filter usually). If what I'm doing is off by a couple pixels, it will entirely ruin the effect unfortunately.

For example, in Dark Basic Professional (EEEK! Sacrelige! Hehheh =) I would simply do something like this:
(image and code)

Image

Code: Select all

` \./  \./  \./  \./  \./  \./  \./  \./  \./  \./  \./  \./
` Simple DarkBasicPro example demonstrating the very simple concept
` of displaying 3D objects in front of 2D bitmaps.  Why should
` this be at all hard in PureBasic/Ogre ?  I'm sure I must have
` missed something obvious in the PureBasic/Ogre docs.
` -- Thanks for any assistance/suggestions!
`      -=VRMan=-  7/27/07
` /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\

set display mode 320, 300, 32 : ` we need a smallish WINDOW (not fullscreen)
set window on : sync rate 60 : sync on : autocam off

` Load the Background Image (what this mini-demo is all about!)
BackgroundImage = 1
load image "Media\VRManLogo01.jpg", BackgroundImage


` Make sumpin to stare at (this cube should end up on top of image...)
ObjCube = 1
make object cube ObjCube, 40
ox# = 0 :  oy# = 20 :  oz# = 100
position object ObjCube, ox#, oy#, oz#
color object ObjCube, rgb(255,0,255)
point camera ox#, oy#, oz#
DISABLE OBJECT ZDEPTH ObjCube

` ~~~~~~~~~~ Main Loop ~~~~~~~~~~~~
AllDone = 0
repeat
    ` FIRST we paste on the background image (for the 3D to be on top of)
    paste image BackgroundImage, 1, 1

    ` by the way: INSTEAD OF PASTING THE IMAGE TO THE WINDOW SURFACE
    ` WE CAN ALTERNATIVELY JUST CALL (after image load)
    `       "TEXTURE BACKDROP BackgroundImage" and this has (almost)
    ` the same affect.

    ` spin the object so this dumb demo isn't entirely boring! =)
    yrotate object ObjCube, wrapvalue(object angle y(ObjCube) + 1)

    ` Sync draws everything and flips the buffers
    ` (corresponds to the Purebasic commands:
    `                   'RenderWorld' then 'FlipBuffers' )
    sync
until AllDone
end : ` ~~~~~~~~~~ end of main loop and end of prog ~~~~~~~
` /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\  /.\

Thanks for any suggestions, I really don't want to use DBPro again and really need all the flexibility that Purebasic offers.

-=VRMan=-

Posted: Fri Jul 27, 2007 10:09 am
by Kaeru Gaman
similar to the way DB does it:

assign a background-picture to a window, and then let openGL put the render output into this window.
the should be a flag somewhere in OGL to make a transparent background.

the DB example you shown is not a screen,
but a render output over a backgroundimage on a window.
(the window's backgroundimage is a property of the window-object)

...also read my above posting...

Hmmmm.... Nope still not a skybox! =) Thanks though...

Posted: Fri Jul 27, 2007 10:35 am
by vrman3d
@Kaeru Gaman:
"yap.
since the idea itself is really uncommon, maybe you are really talking about a skybox/dome. "
Well I won't explain for a 3rd time why a skydome/box won't work, but thanks for the suggestion.
"....since the idea itself is really uncommon...."
Whaaa?
This is certainly not uncommon, but perhaps it may be to Purebasic programmers? Like I showed in the above example, in DarkBasicPro it basically only takes 2 lines to do it - paste the image, then render the 3D junk.

I guess you guys are thinking 'GAME DEV' only, where yeah, usually Hud type thingys go over top the 3D. But in C++ w/Direct3D retained mode it's entirely possible (and easy) and honestly with every other 3D engine I've tried (all of em!) it's just a matter of one line, or perhaps replacing the CLS type command with your BitBlt. One of the first ever 3D dev contracts I had was for NEC, just after DirectX and 3D accell first appeared. It was a window with a 3D model of their desktop machine and beneath was a detailed bitmap with logos and info. The user could click a component in the machine or from the list and we'd animate opening up the case, and fly up to a view. It wasn't a 3D 'world' but rather an 'app' with 3D on top. And that was ... 1995? Hehheh Yipee Matrox Millenium! (Anecdotily, the first 3D accelerators were actually SLOWER in hw HAL mode then using a good software 3d engine like Virtek 3D or Rendermorphics (which MS bought and it became DirectX/Direct3D, whoah what a blast from the past!)

---------------------------------------
Well I'm looking at your suggestion about "redirect the output-channel of the 3D into a sprite/image". Sounds silly complicated but also sounds like it will work. Is there some sort of StartDrawing callback for the 3DOutput()? I can't seem to find it if there is one.

Would you mind explaining your idea in a little more detail? It sounds like it might slow down the render pipeline by 50%, but it's better than I have currently with PB (which is zero, or warped skyboxes). Appreciate your time and effort!

---------------------------------------
ALSO, there are plenty of threads around here where people discuss using an image as a window background
(http://www.purebasic.fr/english/viewtop ... e&start=15)
but it's always in relation to a regular gadget filled window, never anything about the (very different from the rest of the system) 3D output 'screen'.
It seems that no matter what you do to the regular window background brush, the 3D Engine clobbers it by ALWAYS writing across the entire window.

---------------------------------------
Anyway, in my humble opinion there should be a command in PB called:
CameraBackImage(0, LoadTexture(BmpBG, "BG_Texture.jpg"))

obviously very similar (in syntax and function) to:
CameraBackColor(0, RGB(255,255,0))
---------------------------------------


Thanks again for your help everyone, I've always enjoyed the people in this forum!
-=VRMan=-

Well not really

Posted: Fri Jul 27, 2007 10:48 am
by vrman3d
@Kaeru Gaman:
"assign a background-picture to a window, and then let openGL put the render output into this window.
the should be a flag somewhere in OGL to make a transparent background. "
Well actually I'm trying to use OGRE (all the built-in commands in PB) not Ogl... My point to using PB was it's great flexibility, but mainly the simplicity of the Ogre stuff.
the DB example you shown is not a screen,
but a render output over a backgroundimage on a window.
(the window's backgroundimage is a property of the window-object)
Well ya it's not a 'screen' since that's only a Purebasic concept. But it's also not at all "the window's background image as a property", did you see the 'Paste Image imgnum, 1,1' command? That's what's doing the actual BitBlt (Bit block transfer), it's not like creating an 'Image Brush' with the win api. This is much more like a sprite that I'm slapping on the backbuffer, then rendering with the sync. You can move it around by changing the x,y in paste image.

I'd REALLY LIKE to find a way to do what you are describing, but once again, OGRE CLOBBERS IT! @#$#$&@^
It's simple to do that in PB (winapi which I've been doing since the release of "Windows 286", the version before Win3.0, Win For Workgroups, Win95 ..... hehheh long time =):

Code: Select all

hBrush = CreatePatternBrush_(ImageID(BmpSkin))
 	SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush) 
But once again, Ogre/PB clobbers the win background.

Anyone? Anyone?

Posted: Fri Jul 27, 2007 11:04 am
by Kaeru Gaman
first: calm down.

second: stop shouting.

third: calm down.

the OGRE implementation in PB is a bit older, and DX7 based.

> Well ya it's not a 'screen' since that's only a Purebasic concept.
screen is not a PB-only concept.

> Sounds silly complicated
if you know another way to make the render-output's background transparent, tell me.

> This is certainly not uncommon, but perhaps it may be to Purebasic programmers?
well, tell me a usefull usage for it, besides sole demo programming.

> That's what's doing the actual BitBlt (Bit block transfer), it's not like creating an 'Image Brush' with the win api.
so, redirect your render output anywhere you want, then use BitBlt to shove it over your background.
this is almost the same as I suggested using sprites.


and after all, your stile and your tone of posting get's me someway pissed off.
this is not a Service-Hotline, and I'm no mofo service-troll to be shouted at.

so, I have some prawns to fry, cheereo..

Posted: Fri Jul 27, 2007 12:20 pm
by Fluid Byte
Kaeru Gaman wrote:first: calm down.and after all, your stile and your tone of posting get's me someway pissed off.
this is not a Service-Hotline, and I'm no mofo service-troll to be shouted at.
Agreed! Don't be an ass or you get booted! :twisted:

Code: Select all

InitEngine3D() : InitSprite() : InitKeyboard() : InitMouse()

#CameraSpeed = 3

Define.f KeyX, KeyY, MouseX, MouseY

OpenWindow(0,0,0,640,480,"void")
OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)

CreateMesh(0, 100)

SetMeshData(0, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color, ?CubeData2, 8)
SetMeshData(0, #PB_Mesh_Face, ?CubeDataIndex, 12)

CreateEntity(0, MeshID(0), 0)

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,0,1000)

CreateLight(0, RGB(0,0,255),100.0,0,1000)
CreateLight(1, RGB(255,0,0),-100.0,0,1000)

CreateSprite(0,640,480)
StartDrawing(SpriteOutput(0))
For i=0 To 479
	Box(0,i,640,1,i * 255/479)
Next
StopDrawing()

CameraBackColor(0,-1)

Repeat
	EventID = WindowEvent()
	
	ClearScreen(RGB(0, 0, 0))
	
	DisplaySprite(0,0,0)
	
	ExamineKeyboard()
	
	If KeyboardPushed(#PB_Key_Left)
		KeyX = -#CameraSpeed 
	ElseIf KeyboardPushed(#PB_Key_Right)
		KeyX = #CameraSpeed 
	Else
		KeyX = 0
	EndIf
	
	If KeyboardPushed(#PB_Key_Up)
		KeyY = -#CameraSpeed 
	ElseIf KeyboardPushed(#PB_Key_Down)
		KeyY = #CameraSpeed 
	Else
		KeyY = 0
	EndIf	
		
	If ExamineMouse()
		MouseX = -(MouseDeltaX()/10) * #CameraSpeed/2
		MouseY = -(MouseDeltaY()/10) * #CameraSpeed/2
	EndIf
	
	RotateEntity(0,1,1,1)
	
	RotateCamera(0,MouseX,MouseY,RollZ)
	MoveCamera  (0,KeyX, 0,KeyY)
	
	RenderWorld()		
	
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or EventID = #PB_Event_CloseWindow

End

#SQRT13 = 0.57735026

DataSection
	CubeData2:
	
	Data.f -100.0,100.0,-100.0        ; 0 position
	Data.f -#SQRT13,#SQRT13,-#SQRT13  ; 0 normal
	Data.f 255                        ; 0 colour
	Data.f 100.0,100.0,-100.0         ; 1 position
	Data.f #SQRT13,#SQRT13,-#SQRT13   ; 1 normal
	Data.f 255                        ; 1 colour
	Data.f 100.0,-100.0,-100.0        ; 2 position
	Data.f #SQRT13,-#SQRT13,-#SQRT13  ; 2 normal
	Data.f 255                        ; 2 colour
	Data.f -100.0,-100.0,-100.0       ; 3 position
	Data.f -#SQRT13,-#SQRT13,-#SQRT13 ; 3 normal
	Data.f 255                        ; 3 colour
	Data.f -100.0,100.0,100.0         ; 4 position
	Data.f -#SQRT13,#SQRT13,#SQRT13   ; 4 normal
	Data.f 255                        ; 4 colour
	Data.f 100.0,100.0,100.0          ; 5 position
	Data.f #SQRT13,#SQRT13,#SQRT13    ; 5 normal
	Data.f 255                        ; 5 colour
	Data.f 100.0,-100.0,100.0         ; 6 position
	Data.f #SQRT13,-#SQRT13,#SQRT13   ; 6 normal
	Data.f 255                        ; 6 colour
	Data.f -100.0,-100.0,100.0        ; 7 position
	Data.f -#SQRT13,-#SQRT13,#SQRT13  ; 7 normal
	Data.f 255                        ; 7 colour
	
	CubeDataIndex:
	Data.w 0,2,3
	Data.w 0,1,2
	Data.w 1,6,2
	Data.w 1,5,6
	Data.w 4,6,5
	Data.w 4,7,6
	Data.w 0,7,4
	Data.w 0,3,7
	Data.w 0,5,1
	Data.w 0,4,5
	Data.w 2,7,3
	Data.w 2,6,7
EndDataSection

Posted: Fri Jul 27, 2007 1:06 pm
by Kaeru Gaman
*LOL* :lol:
hey Fluid, is there some special trick there?
I don't see one.

so, if the 3D-"World" has no defined background, it's transparent by default?

...then, where was the mofo problem at all?

Posted: Fri Jul 27, 2007 1:36 pm
by Fluid Byte
LMAO guys, you need to read the manual a little more frequently! :wink:
Syntax

CameraBackColor(#Camera, Color)

Description

Changes the #Camera background color. When a new camera is created, there is no background color to allow to mix 2D background and the 3D scene

Parameters

#Camera - The number of the camera you want to change the background color of. This is the value which you used when you created the camera using CreateCamera()

Color - New color of the camera background. RGB() can be used to get a valid color value. If the 'Color' value is '-1', then the background will be transparent (no color).

Posted: Fri Jul 27, 2007 2:04 pm
by Kaeru Gaman
yap.

I just presumed, he had tested it because he said it didn't work. my fault.

next time I'll test the simple way before I suggest a workaround, promise. :mrgreen:

so what a bigmouth.. makes an incledible hussle in two threads for just less than nothing.. what a wonderful way to get started as a new forum user...

PS:
if someone sais
I've been trying to figure this out for a while, tried TONS of ideas, and searched endless threads to no avail....
I presume that he at least RTFM... Image

Posted: Fri Jul 27, 2007 5:48 pm
by vrman3d
@Kaeru Gaman
"first: calm down. second: stop shouting. third: calm down. "
Ehhh? Dood I'm about as calm as they come. And I'll shout if I want LOL! Whoops, shouted that Lol again dagnabbit! (*oh are exclamation points allowed bro?)
I can't believe we are talking about this 'shouting thing' but ok here goes.
"I'd REALLY LIKE to find a way to do what you are describing, but once again, OGRE CLOBBERS IT! @#$#$&@^"
If you try and read this from an objective standpoint, (hopefully) you'll see that I was trying to emphasize that I LIKED YOUR IDEA (I have certainly learned my lesson to only use bold ) I just have a (bad apparently) habit of using CAPS to emphasize like bold, since I live inside plain text (IDE's) editors, and they don't have Bold so I use things like CAPS and Asterisks. I'll try to change the habit!) and the "OGRE CLOBBERS IT!" was certainly not directed at you, but rather the entire forum community not to be a dink at all, but once again only to emphasize that I was really hoping to find a solution and I was frustrated with Ogre, or my inability to find the solution.

Seriously though, I never shouted at *you* (if I was shouting (not my intention) it was for any help and I thought it was obvious it was in a silly way "anyone? anyone?" and I believe I said things (multiple?) like "Appreciate the help", "Thanks", and "Good suggestions".

Why are people always so sensitive and why does it always turn in to this here? It baffles me. For my 'stile' I apologize, I really do, I was just *hoping* (never demanding) for some one who had run across this before to help me somehow, and certainly nothing directed specifically at you, certainly wasn't pressuring you or upset at you, was glad you were responding with some good ideas.

I also said things like this:
"Thanks again for your help everyone, I've always enjoyed the people in this forum! -=VRMan=-"
You said,
"this is not a Service-Hotline, and I'm no mofo service-troll to be shouted at. "
Did I ever say anything like "Where is Kaeru Gaman, I need his help right now, no one else just Kaeru Gaman!!!" or "Kaeru Gaman you mofo troll , why aren't you, and only you helping me faster, better, smarter!!!!!!!!!!!" Dood once again I can't believe we're wasting forum space on this, because either you really mis-interpreted my (I admit perhaps hyper, perhaps over tired? Definitely hyper, excited about my project last night, dunno it's just me) mis-interpreted my capatalized plea for help, or I missed some rule book saying that we can't get excited about our projects and about our code. Sorry I know that sounds sarcastic again, but it just blows me away, I guess it shouldn't. But wow, what a nice welcome back to the forum! Lol.

/sigh Can we just talk about programming now and just drop this? Much appreciated, and trust me, I'll now spend a lot more time thinking about how my post will possibly affect everyone's feelings, and I'll certainly never use CAPS again. And you're probably even more annoyed now since I was sarcastic a couple of times, sorry and I'll certainly try not to be sarcastic again to you.

DOOD (seriously, whoops) doood I liked your help, want your help, appreciate your help, and it was excellent help, I would never ever DEMAND (crap seriously leaving that in because it's just a bad habit, I spend all day and all night in code, and have for 24 years, and there's no bold-face in plain text editors as you know. It's just a habit I have with trying to emphasize something (note there were CAPS *also* in my second post, inside the CODE section - I used caps in there, not because I was yelling at anybody or yelling at the code, but just so it would catch the eye and not be overlooked. I understand now why you considered it yelling, but lets just end with this, Kaeru Gaman-> it didn't dawn on me that I was 'yelling' and that was certainly not my intention.

So can we please all stop flaming VRMan on his first day back to the forums?? Seriously, thanks much appreciated.

Thanks again for everyone's help (I see there are more than just "Kaeru Gaman's" responses in here now) I haven't had a chance to read them yet since I was busy putting out this little fire (and yes I know it was a long post, but come on, it is my first day back posting here in years, I meant no one any disrespect and you guys are ganging up on me and jumping down my throat! I'm just asking please, please be a little bit more tolerant and let's focus on the Code!

@Fluidbyte
"Don't be an ass or you get booted"
I can't believe you'd jump on the bandwagon of beating up on VRMan. For real please go back and read my responses and please note all the thank yous, and appreciate it's, and keep in mind I never thought I was 'shouting' at anyone, I really didn't. Do my responses honestly come across as ass-ish? The last thing I want is a bunch of enemies here from people mis-interpreting my (careless?) capatalizations.

I might just not bother responding to them (to avoid any more potential drama) but will hopefully glean some useful solutions. And once again again, I really do appreciate you guys taking the time to respond. I'm not a dink lol, and am surely sorry if I came across that way.

Shwew! Bye!

Posted: Fri Jul 27, 2007 5:55 pm
by Fluid Byte
Uhmmm..., is your problem fixed?

Posted: Fri Jul 27, 2007 5:58 pm
by Kaeru Gaman
so, if there is any response to the code and information posted within this pathetic sermon, please repeat it so we can read it...

PS:
okey, after I took the time to read all of your post carefully, it just made me show a little friendly smile... ;)

I dunno how long you did not post, but I think I can understand your point,
because I only discovered internet forums three years ago,
and I'm programming for 25 years now....

I think you should pay most attention to the information in Fluid's posts:
he posted an example and quoted the helpfile to give an explanation.

I'm sorry not to have just put you on this, because I never tried such,
and I didn't look up the help and tried a simple example,
because you seemed to say you already did.... ;)
...this is why I suggested a workaround...
classic misunderstanding.

well, I think your problem should be solved by now, if not, let us know.