Skip to main content
gamedev.net
🔒 Locked

Sprite Draw order

Started by BloodLust666 15 replies 1k views
Original Post
BloodLust666
BloodLust666
Ok, i have 2 sprites, one covers the entire screen and one is small. When i call draw, i'm calling "order_fronttoback" the sprite that covers the screen is at 1.0f and the other is at 0.0f, but i only see the bigger one... when i don't draw it, then i see the smaller one, so i know both are being drawn but for some reason the bigger one is one TOP of the smaller one... even though i have the "order_fronttoback" flag triggered...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Mercury
Mercury
Are you sure the depth buffer is enabled?
BloodLust666
BloodLust666
depth buffer? in the IDirect3D9 object?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
ok, i just enabled depth buffer... wasn't there b4 (ha..) but now whenever i try to clear the screen with "targetzbuffer" it fails.. y's this?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
// init code
m_pD3dDeviceCOM->SetRenderState( D3DRS_ZENABLE, m_bZBuffer);

// frame code
m_pD3dDeviceCOM->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0)

the Clear function is what breaks the program
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Evil Steve
Evil Steve
Quote:
Original post by EvilKnuckles666
ok, i just enabled depth buffer... wasn't there b4 (ha..) but now whenever i try to clear the screen with "targetzbuffer" it fails.. y's this?
If you have the debug runtime installed, with the debug output level pumped up enough, it'll say why it fails.
Are you setting the EnableAutoDepthStencil member of your presentation parameters to true and chosing a depth format?
BloodLust666
BloodLust666
ohhhh, i thought the depth stencil was for stencilling not the Zbuffer.. and what's the format for? like A8R8G8B8?

Edit: nv/md, i found the right format: "D3DFMT_D16"
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
wow... ok, it works know, BUT the bigger texture isn't drawing... what should i clear the screen with?

Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 0.0f, 0)
or
Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0)
or what?

i'm using all sprites (it's a 2D game) so all my Z's are between 0.0f and 1.0f
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
also, does this matter? instead of doing Draw(pTex, pRect, pCenter, pPos, Color)
pPos is NULL. the way i'm moving the sprites is by storing the XYZ coordinates in floats, then having a transform matrix and SetTransform()'ing the sprite, then drawing it with a NULL pointer to the position.. does that matter?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
know what i mean?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Armadon
Armadon
Hi there EvilKnuckles666,
How are you doing?

The Problem
Big sprite might be covering the smaller sprite

The Solution
I might be shooting in the dark here but have you tried testing if the order is correct. Render just 2 sprites and see if the way you order them are correct.

Your theory is correct. Would it be possible to see your Sprite declaration and specific draw calls?

I think the big sprite might be covering the little one and causing you to not see it.

Take care buddy. I hope this helps a bit.
PS: Just as a test, swop them around. If this fails please paste the code.
BloodLust666
BloodLust666
well that was the problem for a while, but now the big sprite isn't even drawing...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
the only time the bigger one actually draws now is if i put it at the same Z as the littler one (0.0f) but then again the bigger again is covering the littler one... y isn't it drawing at 1.0f Z?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Armadon
Armadon
Hi there EvilKnuckles666,
Buddy, it's me again ;)

The Problem
Sprites not rendering correctly (order/format problem)

The Solution
I would say that the following might fix your problem

1) Make sure you have enable the AutoDepthStencil
eg: presentParams.EnableAutoDepthStencil = true;
2) Set the AutoDepthStencilFormat
eg: presentParams.AutoDepthStencilFormat = D3DFMT_D24S8;
3) Make sure that you are clearing the depth buffer.
eg: If you don't clear your Z Buffer (Depth buffer) only the sprite at
Z = 0.0f will render
4) Make sure your sprite ordering is correct.
eg: Render sprite at Z = 0.0f
Render sprite at Z = 1.0f


I hope this helps a bit buddy.
CJM
CJM
Hey,

This may be a stupid suggestion, I don't know. Tried rendering the large sprite at something like 0.9f? Maybe 1.0f is being clipped because of the draw planes.

--CJM
BloodLust666
BloodLust666
i did everything you said, every thing is set correctly but the bigger sprite still won't render at anything but 0.0f... i'm clearing the depth buffer to 1.0f, i even tried to clear it at 0.0f and nothing's working...

clearing the depth buffer to a float, what's that mean?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
Could it be a problem with what float i'm clearing the depth buffer with? that's the only thing i can think of...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.