Software rendering in linux

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
punt
Posts: 13
Joined: Fri Jul 09, 2004 7:57 pm

Software rendering in linux

Post by punt »

I came upon this in irrlicht's code:
//! presents a surface in the client area
void CIrrDeviceLinux::present(video::IImage* image)
{
// TODO, display IImage in X, just like in CIrrDeviceWin32::present()
// I'm new to X and did not find out how to do this quickly.
// If someone knows how to display an A1R5G5B5 image in X, just send it
// to me, you'll get a place in the contributors list :)
// With this, the software device would work to in Linux.
}

Now I am not a X coder, but I have done my bit of dabbling. So if this is still the case that is is needed, I figured I may take a shot at it (at least something that perhaps would be enough for others to optimize).

One thing that hits me right off the bat, is I assume irrlicht should make its own color table ? Recall, under X, you wind up giving it a color, and it give back the best match (true color that will be used for it). Or should I just use the default color table of the desktop (less X resources to consume).
punt
Posts: 13
Joined: Fri Jul 09, 2004 7:57 pm

More then present() needed

Post by punt »

I think there is more then the method present() needed. For that method, I did the following:

Code: Select all

//! presents a surface in the client area
void CIrrDeviceLinux::present(video::IImage* image)
{
	os::Printer::log("In CIrrDeviceLinux.", ELL_WARNING);
	
        // TODO, display IImage in X, just like in CIrrDeviceWin32::present()
        // I'm new to X and did not find out how to do this quickly.
        // If someone knows how to display an A1R5G5B5 image in X, just send it
        // to me, you'll get a place in the contributors list :)
        // With this, the software device would work to in Linux.
	/* this variable will store the handle of the newly created pixmap. */
	Pixmap pixmap;

	// Get the dimension of the image
   core::dimension2d<s32> dimension = (*image).getDimension() ;


	/* this variable will contain the color depth of the pixmap to create. */
	/* this 'depth' specifies the number of bits used to represent a color */
	/* index in the color map. the number of colors is 2 to the power of   */
	/* this depth.                                                         */
	//irr::s32 depth = DefaultDepth(display, DefaultScreen(display));
	irr::s32 depth = 32 ;

	/* create a new pixmap, */
	pixmap = XCreatePixmap(display, window, dimension.Width, dimension.Height, depth);
	// Create the graphic context 
	GC gc;

	// If we are going to do color mapping we need the following
	XColor system_color ;

	XGCValues values;
	unsigned long valuemask = 0;
	gc = XCreateGC(display, pixmap, valuemask, &values );
	for (s32 y =0 ; y < dimension.Height; ++y )
	{
		for (s32 x=0 ; x < dimension.Width; ++x)
		{
			// If we were going to map the color
			/*
		   Status rc = XAllocColor(Device->display(),
								colormap,
								&system_color);
			*/
			video::SColor tcolor  = image->getPixel(x,y) ;
			system_color.red = static_cast<unsigned short>(tcolor.getRed()*257) ;
			system_color.blue = static_cast<unsigned short>(tcolor.getBlue() *257) ;
			system_color.green = static_cast<unsigned short>(tcolor.getGreen() *257);
			XAllocColor(display,colormap,&system_color) ;
			// TODO, lookup how to do transparent pixels
		    XSetForeground(display, gc,system_color.pixel );
		    XSetForeground(display,gc, system_color.pixel); 
			XDrawPoint(display, pixmap, gc, x, y);
		}
	}

	// Should we free the pixmap here ? If not, then where, destructor ?
    XFreePixmap(display, pixmap);
}
I know this isn't the most effiecent, but it seemed reasonable to just get something working. I also moved the XColormap declaration in the header file to a class variable, so it could be shared easilyt with this method.


Now, Ihave debug in, and this never gets called. It dies in creating the SoftwareRendering device. haven't debugged that yet, but has anyone else looked into this ?
punt
Posts: 13
Joined: Fri Jul 09, 2004 7:57 pm

in addTexture

Post by punt »

Tracked in down some more, seems to be in addTexture() when using the Software Render under linux.
punt
Posts: 13
Joined: Fri Jul 09, 2004 7:57 pm

ok, in presenter

Post by punt »

Hmm, found the error, was actually in my IImage subclass, so the excerize at least caught that bug (hadn't shown up under opengl, strange). Anyway, clearly the approach I considered for present is way too slow. So will have to investigate it more, and learn some more X.

Also, I have a much better appreciation for what that routine must do. Clearly my approach was to redner a single pixmap, which isnt what should be done. So will have alot more investigation to do.
dingo
Posts: 95
Joined: Tue Mar 09, 2004 5:02 am
Location: Brisbane, Australia
Contact:

Post by dingo »

Good to see a follow linux coder :)

I'm not really but I want to be
-= Want your C code to control real life robots? www.users.on.net/~symes =-
Post Reply