mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-05 18:00:41 +01:00
Simplify example 27 slightly.
Also use tab instead of spaces (as usual in Irrlicht) git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6408 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
d70d96031b
commit
338af5c0ea
|
@ -36,9 +36,6 @@ shader. Therefore, we set texture size in OnSetConstants callback using
|
|||
setVertexShaderConstant function.
|
||||
*/
|
||||
|
||||
IrrlichtDevice* device = 0;
|
||||
video::ITexture* rt = 0;
|
||||
|
||||
class QuadShaderCallBack : public video::IShaderConstantSetCallBack
|
||||
{
|
||||
public:
|
||||
|
@ -48,22 +45,21 @@ public:
|
|||
virtual void OnSetConstants(video::IMaterialRendererServices* services,
|
||||
s32 userData)
|
||||
{
|
||||
core::dimension2d<u32> size = rt->getSize();
|
||||
|
||||
// get texture size array
|
||||
f32 textureSize[] =
|
||||
{
|
||||
(f32)size.Width, (f32)size.Height
|
||||
};
|
||||
|
||||
if ( FirstUpdate )
|
||||
{
|
||||
FirstUpdate = false;
|
||||
TextureSizeID = services->getVertexShaderConstantID("TextureSize");
|
||||
TextureSamplerID = services->getPixelShaderConstantID("TextureSampler");
|
||||
}
|
||||
|
||||
// get texture size array (for our simple example HLSL just needs that to calculate pixel centers)
|
||||
core::dimension2d<u32> size = services->getVideoDriver()->getCurrentRenderTargetSize();
|
||||
f32 textureSize[2];
|
||||
textureSize[0] = (f32)size.Width;
|
||||
textureSize[1] = (f32)size.Height;
|
||||
|
||||
// set texture size to vertex shader
|
||||
services->setVertexShaderConstant(TextureSizeID, reinterpret_cast<f32*>(textureSize), 2);
|
||||
services->setVertexShaderConstant(TextureSizeID, textureSize, 2);
|
||||
|
||||
// set texture for an OpenGL driver
|
||||
s32 textureLayer = 0;
|
||||
|
@ -143,31 +139,17 @@ public:
|
|||
// set the material of screen quad
|
||||
Driver->setMaterial(Material);
|
||||
|
||||
// set matrices to fit the quad to full viewport
|
||||
// set world matrix to fit the quad to full viewport (we only use ETS_WORLD in the shader, so view, projection currently don't matter)
|
||||
Driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||
Driver->setTransform(video::ETS_VIEW, core::IdentityMatrix);
|
||||
Driver->setTransform(video::ETS_PROJECTION, core::IdentityMatrix);
|
||||
|
||||
// draw screen quad
|
||||
Driver->drawVertexPrimitiveList(Vertices, 4, Indices, 2);
|
||||
}
|
||||
|
||||
//! sets a flag of material to a new value
|
||||
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
|
||||
//! Access the material
|
||||
virtual video::SMaterial& getMaterial()
|
||||
{
|
||||
Material.setFlag(flag, newvalue);
|
||||
}
|
||||
|
||||
//! sets the texture of the specified layer in material to the new texture.
|
||||
void setMaterialTexture(u32 textureLayer, video::ITexture* texture)
|
||||
{
|
||||
Material.setTexture(textureLayer, texture);
|
||||
}
|
||||
|
||||
//! sets the material type to a new material type.
|
||||
virtual void setMaterialType(video::E_MATERIAL_TYPE newType)
|
||||
{
|
||||
Material.MaterialType = newType;
|
||||
return Material;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -190,7 +172,7 @@ int main()
|
|||
return 1;
|
||||
|
||||
// create device
|
||||
device = createDevice(driverType, core::dimension2d<u32>(640, 480));
|
||||
IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(640, 480));
|
||||
|
||||
if (device == 0)
|
||||
return 1; // could not create selected driver.
|
||||
|
@ -278,7 +260,7 @@ int main()
|
|||
*/
|
||||
|
||||
// create render target
|
||||
|
||||
video::ITexture* rt = 0;
|
||||
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
|
||||
{
|
||||
rt = driver->addRenderTargetTexture(core::dimension2d<u32>(640, 480), "RTT1");
|
||||
|
@ -312,13 +294,14 @@ int main()
|
|||
|
||||
// we create a screen quad
|
||||
ScreenQuad *screenQuad = new ScreenQuad(driver);
|
||||
video::SMaterial& screenQuadMaterial = screenQuad->getMaterial();
|
||||
|
||||
// turn off mip maps and bilinear filter since we do not want interpolated result
|
||||
screenQuad->setMaterialFlag(video::EMF_USE_MIP_MAPS, false);
|
||||
screenQuad->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
// turn off mip maps and bilinear filter since we do not want interpolated results
|
||||
screenQuadMaterial.setFlag(video::EMF_USE_MIP_MAPS, false);
|
||||
screenQuadMaterial.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
|
||||
// set quad texture to RTT we just create
|
||||
screenQuad->setMaterialTexture(0, rt);
|
||||
screenQuadMaterial.setTexture(0, rt);
|
||||
|
||||
/*
|
||||
Let's create material for the quad. Like in other example, we create material
|
||||
|
@ -351,7 +334,7 @@ int main()
|
|||
}
|
||||
|
||||
// set post processing material type to the quad
|
||||
screenQuad->setMaterialType((video::E_MATERIAL_TYPE)ppMaterialType);
|
||||
screenQuadMaterial.MaterialType = (video::E_MATERIAL_TYPE)ppMaterialType;
|
||||
|
||||
/*
|
||||
Now draw everything. That's all.
|
||||
|
|
Loading…
Reference in New Issue
Block a user