Page 1 of 1

[fixed]OpenGL draw2DLine sometimes draws 2-pixel-thick line

Posted: Thu Nov 19, 2009 5:55 pm
by squisher
Hi,

I'm not sure what causes it unfortunately, but sometimes the GL state is messed up so 1-pixel lines are drawn as 2-pixels.

The problem can only occur with 255 alpha.

COpenGLDriver::draw2DLine calls setRenderStates2DMode(color.getAlpha() < 255, false, false);

If the first parameter (alpha) is true, the problem does not occur.

If it is false, then the problem can *sometimes* occur.

Sorry I can't provide an example to replicate it... drawing the line with 254 alpha is an acceptable workaround for now...

Posted: Thu Nov 19, 2009 8:59 pm
by hybrid
This might be caused by the anti-aliasing. Although this should be disabled for 2d drawings. Can you provide an example which reproduces this?

Posted: Fri Nov 20, 2009 8:39 am
by vins
I have had similar problems. When I have antialiasing disabled in device creation parameters lines are drawn like with 2 pixels. I have to disable antialiasing to each material manually to fix this. When antialiasing is enabled in device creation everything looks ok. Interesting it is that if I disable the antialiasing only to one of the materials - it desn't make any effect. I have to disable antialiasing to all nodes. I'll try to create an example today or tomorrow to reproduce this.

Posted: Fri Nov 20, 2009 8:48 am
by hybrid
Ah, could be that the line anti-aliasing (which does not require the multisampling of the device) is not properly disabled and state checked. Maybe your gfx card does handle lina anti-aliasing also different when multi-sampling is enabled, which could explain the better results when the device has AA enabled. I'll try to check all state changes, but the example would still help a lot.

Posted: Fri Nov 20, 2009 9:41 am
by vins
By the way I'm talking about 3D lines. Now I saw that it's about draw2DLine. I'll try to create an example late tonight when I get home from work.

Posted: Fri Nov 20, 2009 11:07 am
by vins
Ok. I had free time so I made an example. Very simple one.

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


int main()
{
    SIrrlichtCreationParameters params;
    params.AntiAlias = 0;
    params.Bits = 16;
    params.Fullscreen = false;
    params.WindowSize = dimension2d<u32>(640, 480);
    params.DriverType = video::EDT_OPENGL;

    IrrlichtDevice *device = createDeviceEx(params);

	if (!device)
		return 1;

    device->setWindowCaption(L"OpenGL Lines Test");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	if (!mesh){
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );


    if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
	}

	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	SMaterial mat;
	mat.Thickness = 5;
    mat.AntiAliasing = 0;
    node->getMaterial(0).AntiAliasing = 0;

	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();

		driver->draw3DBox(node->getBoundingBox(), SColor(0,255,0,0));
		driver->setMaterial(mat);
		driver->draw2DLine(position2di(10,10), position2di(100,100), SColor(255,0,0,0));


		driver->endScene();
	}

	device->drop();

    return 0;
}
My application is more complex so I don't really now why and when this happens. The above code works corectly because of this lines:

Code: Select all

mat.AntiAliasing = 0;
node->getMaterial(0).AntiAliasing = 0;
the result is:
Image

If I remove those lines or only one of them the result is: Image

If I remove this line:

Code: Select all

driver->draw2DLine(position2di(10,10), position2di(100,100), SColor(255,0,0,0));
then everything renders ok.

It also looks like "mat.Thickness = 5;" doesn't work. Makes no difference if it 0,1,2,3...

In my application I render to 4 different view ports and this happens only on one of them - the first one I render. It also happens when I render to only one viewport.

PS:The above results was on the computer here at work with a very old Radeon(9550) video. I tried to enable antialias to device creation and all materials. It also renders fine as it does home but the result is as if the video card desn't support antialiasing.

Posted: Wed Jan 06, 2010 5:30 pm
by bitplane
Thanks for the test case, I've added the bug to the tracker

Posted: Thu Jan 07, 2010 10:45 am
by hybrid
This was already fixed for 1.7, where you can also change the 2d material and hence get properly drawn thick lines and toggle anti-aliasing.