Texture pixel screen pixel

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

Texture pixel screen pixel

Post by MolokoTheMole »

I need some help.
I have a 512x512 texture floating in front of the camera on a plane. Now I want to setup the camera (distance) so that 1 texture pixel is exactly 1 screen pixel. The screen resolution and FOV is given. How do I calculate the camera distance?
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

You can't do it with a perspective camera, since not all parts of the texture will be at the same distance.

If you really need this to be texel/pixel perfect, then you'll have to use an orthographic camera. See matrix4f::buildProjectionMatrixOrthoLH() and ICameraSceneNode::setProjectionMatrix().

If you build the projection matrix using the screen height and width, then your object sizes will correspond 1:1 to pixels, i.e. make your texture object the same height and width as its texture and it will come out close to 1:1 . Note that fp maths may produce some inconsistencies though.

Alternatively, since you have a texture, can't you just use IVideoDriver::draw2DImage() to draw it to screen? If you need the screen position of a 3d object, you can use ISceneCollisionManager::getScreenCoordinatesFrom3DPosition() to get it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

If you need to have stuff in front of the texture just use a screen quad with zwriteenable disabled.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
MolokoTheMole
Posts: 109
Joined: Tue Jan 09, 2007 1:18 pm

Post by MolokoTheMole »

It's sort of a 2D/3D engine. Like Duke Nukem Manhattan. So it's 2D but I want it to look as best as possible from a 3D perspective with all the benefits like zooming, maybe slight tilting. So it doesnt have to be perfect but the textures on the map and player should approximate 1:1 correspondence with screen pixels.

--EDIT--
OK works with ortho camera. Thanks a lot!
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

My idea would be to use a vertex shader to place the quad.
I'm using the following shader:

Code: Select all

varying vec2 vTexCoord;
void main(void)
{
	vec2 Position;
	Position.xy = sign(gl_Vertex.xy);
	gl_Position = vec4(Position.xy, 0.0, 1.0);
	vTexCoord = Position.xy *.5 + .5;
}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply