PDA

View Full Version : Textures render perfectly on emulator, all white on galaxy nexus.



Lee Morton
04-20-2012, 12:52 PM
ported my game from Irrlicht to Proton using the Proton-Irrlicht and have everything working on the emulator, but as soon as i run it on my galaxy nexus, all textures render white. game is 2D using ortho projection. render code is.



irr::video::IVideoDriver *driver = device->getVideoDriver();

scene::ICameraSceneNode *cam = (scene::ICameraSceneNode *)device->getSceneManager()->getSceneNodeFromType(scene::ESNT_CAMERA);

if(cam == NULL)
{
cam = device->getSceneManager()->addCameraSceneNode();
}

core::matrix4 matproj;
matproj.buildProjectionMatrixOrthoLH(SCREEN_WIDTH, -SCREEN_HEIGHT, -100.0f, 100.0f);
matproj.setTranslation(core::vector3df(1, 1, 0));

cam->setProjectionMatrix(matproj, true);




void Draw2D::DrawImage(irr::video::ITexture* texture , irr::core::vector2df position, irr::core::dimension2di size, irr::core::rect<irr::s32> sourceRect, irr::f32 rotation, irr::video::SColor color, irr::core::position2d<irr::s32> rotationPoint)
{
if(texture == NULL || device == NULL)
return;

irr::video::IVideoDriver *driver = device->getVideoDriver();

if(!size.Width || !size.Height)
{
size.Width = texture->getSize().Width;
size.Height = texture->getSize().Height;
}

if(!sourceRect.getWidth() || !sourceRect.getHeight())
{
sourceRect.UpperLeftCorner.X = 0;
sourceRect.UpperLeftCorner.Y = 0;
sourceRect.LowerRightCorner.X = texture->getSize().Width;
sourceRect.LowerRightCorner.Y = texture->getSize().Height;
}
else
{
sourceRect.LowerRightCorner.X += sourceRect.UpperLeftCorner.X;
sourceRect.LowerRightCorner.Y += sourceRect.UpperLeftCorner.Y;
}

if(rotationPoint == irr::core::position2d<irr::s32>(-1, -1))
rotationPoint = irr::core::position2d<irr::s32>((size.Width / 2) + position.X, (size.Height / 2) + position.Y);

irr::video::SMaterial material;

// Find the positions of corners
irr::core::vector2df corner[4];

corner[0] = irr::core::vector2df(position.X, position.Y);
corner[1] = irr::core::vector2df(position.X + size.Width, position.Y);
corner[2] = irr::core::vector2df(position.X, position.Y + size.Height);
corner[3] = irr::core::vector2df(position.X + size.Width, position.Y + size.Height);

// Rotate corners
if(rotation != 0.0f)
for(int x = 0; x < 4; x++)
corner[x].rotateBy(rotation,irr::core::vector2df(rotationPo int.X, rotationPoint.Y));


// Find the uv coordinates of the sourceRect
irr::core::vector2df uvCorner[4];
uvCorner[0] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[1] = irr::core::vector2df(sourceRect.LowerRightCorner.X , sourceRect.UpperLeftCorner.Y);
uvCorner[2] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.LowerRightCorner.Y);
uvCorner[3] = irr::core::vector2df(sourceRect.LowerRightCorner.X , sourceRect.LowerRightCorner.Y);
for(int x = 0; x < 4; x++)
{
float uvX = uvCorner[x].X/(float)texture->getSize().Width;
float uvY = uvCorner[x].Y/(float)texture->getSize().Height;

Clamp(uvX, 0.0, 1.0);
Clamp(uvY, 0.0, 1.0);

uvCorner[x] = irr::core::vector2df(uvX,uvY);
}

// Vertices for the image
irr::video::S3DVertex vertices[4];
irr::u16 indices[6] = { 0, 1, 2, 3 ,2 ,1 };

for(int x = 0; x < 4; x++)
{
vertices[x].Pos = irr::core::vector3df(corner[x].X,corner[x].Y, 0);
vertices[x].TCoords = uvCorner[x];
vertices[x].Color = color;
}
material.Lighting = false;
material.ZWriteEnable = false;
material.TextureLayer[0].Texture = texture;
material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP;
material.TextureLayer[0].TextureWrapV = video::ETC_CLAMP;
//material.MaterialType = irr::video::ETC_CLAMP;
//material.Wireframe = true;
material.ZBuffer = video::ECFN_NEVER;
material.setFlag(video::EMF_BILINEAR_FILTER, true);

material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;

driver->setMaterial(material);
driver->drawIndexedTriangleList(vertices, 4, indices, 2);

//__android_log_print(ANDROID_LOG_INFO, "Irrlicht", "texture size is %d x %d", texture->getSize().Width, texture->getSize().Height);
}


thanks for any help.

Seth
04-20-2012, 01:23 PM
ported my game from Irrlicht to Proton using the Proton-Irrlicht and have everything working on the emulator, but as soon as i run it on my galaxy nexus, all textures render white. game is 2D using ortho projection. render code is.



Hmm, can you try the RT3DApp example on your phone? If the Quake example gets white textures, but the rest of the demos in that app work ok, I might have an idea of how to fix it.

Lee Morton
04-20-2012, 01:53 PM
thank you for the reply.

yes everything is textured except quake3 map

Seth
04-20-2012, 09:49 PM
thank you for the reply.

yes everything is textured except quake3 map

Ok, good, because the same thing happens on one of my devices so that means I have a way to duplicate/fix it, and if I do that, it will probably fix your game.

Can't give a good time estimate on when I can do that though, except it won't be in the next 48 hours, Ludumdare 48 is about to start! :sweatdrop:

Lee Morton
04-21-2012, 06:25 AM
thanks, and good luck.

Lee Morton
04-23-2012, 02:35 PM
Just wondering, what is actually causing this problem?

Thanks

Seth
04-25-2012, 06:37 AM
Fixed on svn. Irrlicht was trying to convert the RGB of the embedded lightmap to ABGR and the Adreno 205 (Tegra2 also) didn't like it I guess. :sweatdrop:

Lee Morton
04-25-2012, 11:37 AM
Thank you.

but still a little problem,

the first texture loads and renders correctly. once my scene changes everything is white again. im not sure if this is my code, android sytem or irrlicht. but my game loads textures when needed and not on game load.

any insight?

Seth
04-25-2012, 12:06 PM
Does the RT3DApp Quake example now work on your phone, including if you enter/exit/enter the level?

It does work here, so I'd need a small example showing how to reproduce it if it's something in irrlicht/proton I could fix.

Note: It does crash when going to the home screen and back though.. I assume because Irrlicht doesn't handle reloading the lightmap texture from the bsp which Android needs after losing focus...

Lee Morton
04-25-2012, 02:02 PM
still only see lightmaps on quake level.

Seth
04-25-2012, 11:03 PM
still only see lightmaps on quake level.

Hmm, it may be a problem specific to that graphic chip (PowerVR SGX540 it looks like) - unfortunately until I have a phone with that chip I won't be able to reproduce or fix the problem. :wheelchair:

Lee Morton
05-08-2012, 04:29 PM
well. completly rewrite almost everything. now only uses proton not irrlicht at all. and works perfectly.

thanks for a great library.