OpenGL and createScreenShot() issue with odd border

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
scotchfaster
Posts: 15
Joined: Sun Feb 24, 2008 4:27 am

OpenGL and createScreenShot() issue with odd border

Post by scotchfaster »

Some rambling context: for this project I've needed to render to an offscreen bitmap. I've waffled between rendering to a texture or calling createScreenShot(). The problem with the texture is that apparently I can't get access to bitmap data using lock() on OpenGL. This is a problem for me.

I was reluctant to use createScreenShot() because I'd read it was slow. However, I actually find it quite fast on OpenGL - on my system it seems to take around .02 seconds to create a 640 x 480 24 bit screenshot.

So first, a question: is this some abnormality on my system? I don't have a wide range of hardware to test with?

And now to the bug: the problem is that the screenshot that's created seems to have an odd black border on the top and bottom which I don't see on screen in the rendering window. I see this both when I examine the bitmap bits, and also in the resulting bitmap when I call writeImageToFile().

I can work around this, I'd just prefer not to. Any ideas?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Please paste your code. My screenshots don't have any border.
scotchfaster
Posts: 15
Joined: Sun Feb 24, 2008 4:27 am

Post by scotchfaster »

Here you go. The result of calling renderTest() is the file "C:\out.bmp", which is blue but with a black area on the top and right. Thanks for looking at this.

Code: Select all

#include <irrlicht.h>
#include <windows.h>

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

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#include <windows.h>
#endif

static const int kWidth = 640;
static const int kHeight = 480;

// local globals
IrrlichtDevice *gDevice = NULL;
IVideoDriver* gDriver = NULL;
ISceneManager* gSmgr = NULL;
IGUIEnvironment* guienv = NULL;
IAnimatedMesh* gMesh = NULL;

void * InitializeHiddenWindow ( void );
void renderTest();

void renderTest()
{
	SIrrlichtCreationParameters params;
	params.AntiAlias = true;
	params.DriverType = EDT_OPENGL;
	params.WindowId = NULL;
	params.WindowSize.Height = kWidth;
	params.WindowSize.Width = kHeight;
	params.WindowId = InitializeHiddenWindow();
	params.Bits = 24;
	gDevice = createDeviceEx ( params );

	/*
	Get a pointer to the video gDriver, the SceneManager and the
	graphical user interface environment, so that
	we do not always have to write gDevice->getVideoDriver(),
	gDevice->getSceneManager() and gDevice->getGUIEnvironment().
	*/

	gDriver = gDevice->getVideoDriver();
	gSmgr = gDevice->getSceneManager();
	guienv = gDevice->getGUIEnvironment();

	gSmgr->addCameraSceneNode(0, vector3df(0,0,400), vector3df(0,0,0));

	gDriver->beginScene(true, true, SColor(255,100,101,140));

	gSmgr->drawAll();
	guienv->drawAll();

	gDriver->endScene();

	video::IImage* image = gDevice->getVideoDriver()->createScreenShot();

	if (image)
	{
		gDevice->getVideoDriver()->writeImageToFile(image, "c:\\out.bmp"); 
		image->drop();
	}

}

static LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

static void * InitializeHiddenWindow ( void )
{
	extern HINSTANCE gInstance;
	const TCHAR * Win32ClassName = L"AttuneCam Render Class";

	WNDCLASSEX wcex;
	wcex.cbSize			= sizeof(WNDCLASSEX);
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)CustomWndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= DLGWINDOWEXTRA;
	wcex.hInstance		= gInstance;
	wcex.hIcon			= NULL;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= Win32ClassName;
	wcex.hIconSm		= 0;

	RegisterClassEx(&wcex);


	int width = kWidth;
	int height = kHeight;

	HWND hWnd = CreateWindow(
		Win32ClassName,
		L"AttuneCam Render Window",
		WS_OVERLAPPEDWINDOW & ~WS_VISIBLE,
		0,0, //-kWidth, -kHeight,
		width, height,
		NULL,
		NULL,
		gInstance,
		NULL
	);

	return hWnd;
}
Last edited by scotchfaster on Sun Mar 02, 2008 6:53 am, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Please, god, help newbies to use

Code: Select all

 tags when they post code. Amen.
scotchfaster
Posts: 15
Joined: Sun Feb 24, 2008 4:27 am

Post by scotchfaster »

Okay...should I repost my code between

Code: Select all

...
?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Don't repost. Just edit your original post and add the necessary

Code: Select all

 tags.

I hope my previous post didn't come off as rude. The whole code tag thing seems to be a recurring issue, and I just thought it would be a funny way to ask you to use them.

Travis
scotchfaster
Posts: 15
Joined: Sun Feb 24, 2008 4:27 am

Post by scotchfaster »

vitek wrote:Don't repost. Just edit your original post and add the necessary

Code: Select all

 tags.

I hope my previous post didn't come off as rude. The whole code tag thing seems to be a recurring issue, and I just thought it would be a funny way to ask you to use them.

Travis[/quote]

Well, the anger management classes seem to be working... :wink: 

Done - looks much better. Thanks.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

scotchfaster wrote:Well, the anger management classes seem to be working... :wink:
I've never seen vitek angry since I came here..never.. :roll:
:D
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply