IVideoDriver request : draw2DPixel
IVideoDriver request : draw2DPixel
I took a look in a few of the video drivers and it looks like it would be fairly trivial to add a draw2DPixel function.
Would this be accepted in Irrlicht?
Thanks
Would this be accepted in Irrlicht?
Thanks
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
I can't speak for the SVN devs, but I was looking for such a method recently and was surprised to find it missing.
Are you proposing to supply an implementation for a range of drivers? That would be ideal.
Are you proposing to supply an implementation for a range of drivers? That would be ideal.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Which drivers are you proposing to modify yourself?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
alright i took a quick look at the software drivers and the opengl driver. i'm at work right now and unable to actually test this, but i'll post the patch i made up now (and then test it at home).
will definitely need a volunteer for the directx implementation because i don't own a windows machine.
so here are 2 patch files, one for IVideoDriver, and the other for the opengl, software, and software2 driver:
ps. sorry if i haven't prepared the patch in the correct way, if not i'll fix it when i'm at home
will definitely need a volunteer for the directx implementation because i don't own a windows machine.
so here are 2 patch files, one for IVideoDriver, and the other for the opengl, software, and software2 driver:
Code: Select all
Index: IVideoDriver.h
===================================================================
--- IVideoDriver.h (revision 1640)
+++ IVideoDriver.h (working copy)
@@ -590,6 +590,12 @@
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255)) = 0;
+ //! Draws a pixel.
+ /** \param x: x coordinate of the pixel.
+ \param y: y coordinate of the pixel.
+ \param color: Color of the pixel to draw. */
+ virtual void drawPixel(u32 x, u32 y, const SColor &color) = 0;
+
//! Draws a non filled concyclic regular 2d polyon.
/** This method can be used to draw circles, but also
triangles, tetragons, pentagons, hexagons, heptagons, octagons,
Code: Select all
Index: COpenGLDriver.cpp
===================================================================
--- COpenGLDriver.cpp (revision 1640)
+++ COpenGLDriver.cpp (working copy)
@@ -1488,7 +1488,19 @@
}
+//! Draws a pixel
+void COpenGLDriver::drawPixel(u32 x, u32 y, const SColor &color)
+{
+ disableTextures();
+ setRenderStates2DMode(color.getAlpha() < 255, false, false);
+ glBegin(GL_POINTS);
+ glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
+ glVertex2i(x, y);
+ glEnd();
+}
+
+
bool COpenGLDriver::setTexture(u32 stage, const video::ITexture* texture)
{
if (stage >= MaxTextureUnits)
Index: COpenGLDriver.h
===================================================================
--- COpenGLDriver.h (revision 1640)
+++ COpenGLDriver.h (working copy)
@@ -201,6 +201,9 @@
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255));
+ //! Draws a pixel
+ virtual void drawPixel(u32 x, u32 y, const SColor &color);
+
//! Draws a 3d line.
virtual void draw3DLine(const core::vector3df& start,
const core::vector3df& end,
Index: CSoftwareDriver.cpp
===================================================================
--- CSoftwareDriver.cpp (revision 1640)
+++ CSoftwareDriver.cpp (working copy)
@@ -813,7 +813,13 @@
}
+//! Draws a pixel
+void CSoftwareDriver::drawPixel(u32 x, u32 y, const SColor &color)
+{
+ ((CImage*)BackBuffer)->setPixel(x, y, color);
+}
+
//! draw a 2d rectangle
void CSoftwareDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip)
Index: CSoftwareDriver.h
===================================================================
--- CSoftwareDriver.h (revision 1640)
+++ CSoftwareDriver.h (working copy)
@@ -83,6 +83,9 @@
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255));
+ //! Draws a pixel
+ virtual void drawPixel(u32 x, u32 y, const SColor &color);
+
//! \return Returns the name of the video driver. Example: In case of the Direct3D8
//! driver, it would return "Direct3D8.1".
virtual const wchar_t* getName() const;
Index: CSoftwareDriver2.cpp
===================================================================
--- CSoftwareDriver2.cpp (revision 1640)
+++ CSoftwareDriver2.cpp (working copy)
@@ -1579,6 +1579,13 @@
}
+//! Draws a pixel
+void CBurningVideoDriver::drawPixel(u32 x, u32 y, const SColor &color)
+{
+ ((CImage*)BackBuffer)->setPixel(x, y, color);
+}
+
+
//! draw an 2d rectangle
void CBurningVideoDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos,
const core::rect<s32>* clip)
Index: CSoftwareDriver2.h
===================================================================
--- CSoftwareDriver2.h (revision 1640)
+++ CSoftwareDriver2.h (working copy)
@@ -99,6 +99,9 @@
const core::position2d<s32>& end,
SColor color=SColor(255,255,255,255));
+ //! Draws a pixel
+ virtual void drawPixel(u32 x, u32 y, const SColor &color);
+
//! \return Returns the name of the video driver. Example: In case of the DirectX8
//! driver, it would return "Direct3D8.1".
virtual const wchar_t* getName() const;
Ok I fixed an error or two I had made in my patches. I have tested them and everything appears to be working fine.
trivial test case:
thanks
trivial test case:
Code: Select all
#include "irrlicht.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")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
int main()
{
IrrlichtDevice *device = createDevice( video::EDT_BURNINGSVIDEO, dimension2d<s32>(640, 480), 16, false, false, false, 0);
if (!device)
return 1;
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
for(u32 x = 0; x < 640; x++) {
for(u32 y = 0; y < 480;) {
driver->drawPixel(x, y, SColor(255, 255, 0, 255));
y += 25;
}
}
driver->endScene();
}
device->drop();
return 0;
}
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Heh. Heheheh. Or can I? Heeeeehahahahah.rogerborg wrote:I can't speak for the SVN devs.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Committed in SVN 1642. Many thanks for the API and implementations.
Test code follows:
Test code follows:
Code: Select all
#include "irrlicht.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")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
bool runTestWithDriver(E_DRIVER_TYPE driverType)
{
IrrlichtDevice *device = createDevice( driverType, dimension2d<s32>(640, 480));
if (!device)
if(EDT_DIRECT3D8 == driverType || EDT_DIRECT3D9 == driverType)
return true; // Might not be built in.
else
return false;
IVideoDriver* driver = device->getVideoDriver();
ISceneManager * smgr = device->getSceneManager();
// Draw a cube to check that the pixels' alpha is working.
ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
cube->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
cube->setMaterialFlag(video::EMF_LIGHTING, false);
(void)smgr->addCameraSceneNode();
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
// Test for out-of-range values as well as valid ones.
for(s32 x = -10; x < 650; ++x)
{
s32 y = 480 * x / 640;
driver->drawPixel((u32)x, (u32)y, SColor(255, 255 * x / 640, 255 * (640 - x) / 640, 0));
y = 480 - y;
driver->drawPixel((u32)x, (u32)y, SColor(255 * x / 640, 0, 255, 255));
}
driver->endScene();
IImage * screenshot = driver->createScreenShot();
bool result = true;
if(screenshot)
{
stringc filename(driver->getName());
filename += ".png";
result = driver->writeImageToFile(screenshot, filename.c_str());
screenshot->drop();
stringc openFile("\"");
openFile += filename;
openFile += "\"";
(void)system(openFile.c_str());
}
device->drop();
return result;
}
int main()
{
bool passed = true;
passed &= runTestWithDriver(EDT_NULL);
passed &= runTestWithDriver(EDT_SOFTWARE);
passed &= runTestWithDriver(EDT_BURNINGSVIDEO);
passed &= runTestWithDriver(EDT_OPENGL);
passed &= runTestWithDriver(EDT_DIRECT3D8);
passed &= runTestWithDriver(EDT_DIRECT3D9);
return passed ? 0 : 1;
}
Last edited by rogerborg on Fri Oct 24, 2008 7:41 pm, edited 1 time in total.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way