Draw a single pixel

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
spyro
Posts: 17
Joined: Mon Mar 14, 2005 4:05 pm

Draw a single pixel

Post by spyro »

Is the drawing of single pixels in Irrlicht possible, when not, how it could be done?
I've searched for this feature today, but I've found nothing.

Thanks for your help :)
spyro
Last edited by spyro on Thu Aug 10, 2006 5:16 pm, edited 1 time in total.
My Forum Link
AndyCR
Posts: 110
Joined: Tue Nov 08, 2005 2:51 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

you could always use drawrectangle (think thats the name, never used it) and just make the rectangle be one pixel.
cadue
Posts: 72
Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano

Post by cadue »

but in this way there is a ugly performance! Using OPENGL is certain possible! there was a function, GL_BEGIN(POINT)... or at leas a similar funtion...sorry, i don't remember :oops:
excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
spyro
Posts: 17
Joined: Mon Mar 14, 2005 4:05 pm

Post by spyro »

Where can i find this function?
In the OpenGL libraries or in the basic functions of Irrlicht?
If the function is in the OpenGL libraries, could it be combined with Irrlicht or not?
PS: Sorry, for my English :D

spyro
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

That method is from OpenGL. To integrate with Irrlicht it would be best to add a new method to IVideoDriver named draw3DPoint and add implementations for all video driver implementations.
spyro
Posts: 17
Joined: Mon Mar 14, 2005 4:05 pm

Post by spyro »

It sounds a little bit difficult, isn't it?
But i will try it soon. :wink:
Thank's for your help!

spyro
juliusctw
Posts: 392
Joined: Fri Apr 21, 2006 6:56 am
Contact:

share it with us

Post by juliusctw »

hey spyro

if you got it workin , share it with us :)
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

spyro:

you could integrate OpenGl stuff easlly with yor Irrlicht program, so you do not have to rechange the engine.

here is example that showing you how to a point. it is part from Magic Library.

Code: Select all

/****************************************
    draw a pixel by using OpenGl
        
        By Emil Halim

****************************************/


// ViewOrtho,ViewPerspective,Plot are
// parts of MagicLibrary.

#include "windows.h"
#include "gl/gl.h"
#include "gl/glu.h"
#include "gl/glaux.h"
#include "gl/glext.h"
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;



#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib,"opengl32.lib")


void ViewOrtho()            
{
 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
 glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE);
 glDisable(GL_LIGHTING);
 glDisable(GL_DEPTH_TEST);
 glDisable(GL_CULL_FACE);
 glMatrixMode(GL_PROJECTION);        
 glPushMatrix();            
 glLoadIdentity();           
 glOrtho( 0, 640 , 480 , 0, -10, 10 ); 
 glMatrixMode(GL_MODELVIEW);         
 glPushMatrix();            
 glLoadIdentity();           
}

void ViewPerspective()           
{
 glMatrixMode( GL_PROJECTION );        
 glPopMatrix();            
 glMatrixMode( GL_MODELVIEW );        
 glPopMatrix();            
 glEnable(GL_DEPTH_TEST);
 glEnable(GL_CULL_FACE);
}


void Plot (float x, float y)
{
    glBegin(0);
    glVertex2f(x,y);
    glEnd();
}

int main()
{
  IrrlichtDevice *device =
		createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16);

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

  while(device->run())
   {

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

		ViewOrtho();

                /// draw a pixel at 100,200
                Plot (100, 200);

                ViewPerspective();    
                
                smgr->drawAll();
		
		driver->endScene();
   }

   device->drop();
   return 0;
}
so as you see ,merging opengl is so easy.

hope it help you.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Emil, the point is that this will work *ONLY* for OpenGL. Adding a generic point drawing routine would enable the use of any driver. Furthermore you could add several vertices to draw a point cloud in a performant way. Of course you could also add a driver check in the code, but adding an additional method would allow for easy integration with Irrlicht core. I guess that such basic but useful additions could easily make it into the core.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

ok hybrid, i got you idea.

but i really donot know how to draw 2D vertices in DirectX,so if anyone knows please post it to make it standard routine and adding it to the core of engine.
spyro
Posts: 17
Joined: Mon Mar 14, 2005 4:05 pm

Post by spyro »

Looks cool! :D
I will try it with OpenGl and thanks for your help.
spyro
Posts: 17
Joined: Mon Mar 14, 2005 4:05 pm

Post by spyro »

How can I use glColor4f(red, green, blue, alpha)?
I've tried it, but nothing happened.
Any Ideas?

Here is my current code (thanks to Emil_halim for his example):

Code: Select all

#include "gl/gl.h"

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;

int main()
{
    IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16);

    IVideoDriver* driver = device->getVideoDriver();
  
    glOrtho( 0, 800 , 600 , 0, -10, 10 );           

    while(device->run())
    {
        driver->beginScene(true, true, SColor(0,255,255,255));
        glBegin(GL_POINTS);
        glColor4f(0,255,0,0);
        glVertex2f(10,10);
        glEnd();
        driver->endScene();
    }

    device->drop();
    return 0;
}

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

Post by vitek »

You might have a peek at the SVN version of SMaterial and the derived IVideoDriver implementations. Our friend hybird added a material flag that allows vertices to be rendered as points.

Oh, and the problem that you're seeing is most likely caused by not setting up any of the transforms.

Travis
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

spyro wrote:How can I use glColor4f(red, green, blue, alpha)?
I've tried it, but nothing happened.
Any Ideas?

Here is my current code (thanks to Emil_halim for his example):

Code: Select all

        glColor4f(0,255,0,0);
       
thanks spyro

the last parametr is the alpha value try to replace it with the next line

Code: Select all

       glColor4f(0,255,0,1.0);
Edited: this will work, i have test it.

Code: Select all

                driver->beginScene(true, true, SColor(0,0,0,0));

                 ViewOrtho();
                 glBegin(GL_POINTS);
                 glColor4f(0,255,0,1.0);
                 glVertex2f(10,10);
                 glEnd();
                 ViewPerspective();

                 smgr->drawAll();

	                 driver->endScene();
spyro
Posts: 17
Joined: Mon Mar 14, 2005 4:05 pm

Post by spyro »

I've tried it but nothing changed.
Maybe the transforms cause this problem like vitek wrote.
I will see for it.

Edit: I've tried it and it works now! Thank you! :D
Post Reply