How to display a model on top of textures? [XNA]

Started by
13 comments, last by kauna 12 years, 4 months ago
Yup, and lighting seems to work fine when not using a rendetarget.
Advertisement
Take a step back for a minute. Do you really need to use a render target at all?

Just draw all your 2d GUI, then draw the models on top. That should work unless you're actually using the depth buffer when drawing your GUI. But assuming you're drawing it with SpriteBatch, depth-writing is disabled by default.

Once you've done drawing the GUI, then set the appropriate states for rendering 3d models (enable the depth buffer, enable depth writing, turn off alpha blending) and draw your model.

(btw, it looks like you're using XNA 3.0. I would consider upgrading to XNA 4.0. The API has had a number of improvements that make it more difficult to do the wrong thing :-)).

Take a step back for a minute. Do you really need to use a render target at all?
Just draw all your 2d GUI, then draw the models on top. That should work unless you're actually using the depth buffer when drawing your GUI. But assuming you're drawing it with SpriteBatch, depth-writing is disabled by default.
Once you've done drawing the GUI, then set the appropriate states for rendering 3d models (enable the depth buffer, enable depth writing, turn off alpha blending) and draw your model.
(btw, it looks like you're using XNA 3.0. I would consider upgrading to XNA 4.0. The API has had a number of improvements that make it more difficult to do the wrong thing :-)).

[font="Arial"]
[/font][font="Arial"]Otherwise, there is still some improvement for the code with render target :[/font]
[font="Arial"] [/font]
[font="Arial"]- you can clear your render target and depth buffer with one call. No need to call clear twice (this isn't an error though).[/font]
[font="Arial"]- Projection matrix : you have to calculate correct projection matrix to use with the render target. You may not use the same projection matrix as with the full screen since the aspect ratio is different.[/font]
[font="Arial"]- [color="#1C2837"]SurfaceFormat.Color should be the correct color buffer format[/font]
[color="#1C2837"][font="Arial"] [/font]
[color="#1C2837"][font="Arial"]However, I can't think why your model shows up black.[/font]
[color="#1C2837"][font="Arial"] [/font]
[color="#1C2837"][font="Arial"]Cheers![/font]
[color="#1C2837"][font="Arial"]SurfaceFormat.Color should be the correct color buffer format[/quote][/font]
[color="#1C2837"][font="Arial"] [/font]
[font="Arial"][color="#1c2837"]What?[/font]
[font="Arial"] [/font]
[font="Arial"][color="#1c2837"]... I'm thinking that the current aspectratio might be banning me from using non-power-of-two-textures... but I'm not sure.[/font]

[color="#1C2837"][font="Arial"]SurfaceFormat.Color should be the correct color buffer format
[/font]
[color="#1C2837"]
[font="Arial"][color="#1c2837"]What?[/font]
[font="Arial"] [/font]
[font="Arial"][color="#1c2837"]... I'm thinking that the current aspectratio might be banning me from using non-power-of-two-textures... but I'm not sure.[/font]
[/quote]

Well I guess it's my turn to say "what"?
[color=#1C2837][font=Arial][size=2]By saying "Color buffer format" I mean render target format. As you are storing color in it it is correct to say "color buffer". You'll need RGB channels for your render target and 8-bits per channel is enough. The closest thing to that is a surface format RGBA with 8-bits per channel. [/font][color=#1C2837][font=Arial][size=2]SurfaceFormat.Color[/font][color=#1C2837][font=Arial][size=2] stands for such surface format. [/font]
[color=#1C2837][font=Arial][size=2]
[/font]
[color=#1C2837][font=Arial][size=2]Nothing is banning you from using non-power-of-two-textures except the hardware if it doesn't support them (which is rare these days). [/font]
[font="Arial"][color="#1c2837"]Just calculate a correct projection matrix to reflect the size / aspect of the render target.[/font]
[font="Arial"][color="#1c2837"]
[/font]
[font="Arial"][color="#1c2837"]Cheers![/font]
[font="Arial"][color="#1c2837"]
[/font]


This topic is closed to new replies.

Advertisement