Page 1 of 1

Draw a single pixel

Posted: Sat Jul 15, 2006 5:30 pm
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

Posted: Sat Jul 15, 2006 6:08 pm
by AndyCR
you could always use drawrectangle (think thats the name, never used it) and just make the rectangle be one pixel.

Posted: Sat Jul 15, 2006 6:19 pm
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:

Posted: Sun Jul 16, 2006 9:34 am
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

Posted: Sun Jul 16, 2006 1:10 pm
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.

Posted: Sun Jul 16, 2006 1:38 pm
by spyro
It sounds a little bit difficult, isn't it?
But i will try it soon. :wink:
Thank's for your help!

spyro

share it with us

Posted: Tue Jul 18, 2006 1:50 pm
by juliusctw
hey spyro

if you got it workin , share it with us :)

Posted: Tue Jul 18, 2006 2:31 pm
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.

Posted: Tue Jul 18, 2006 2:52 pm
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.

Posted: Tue Jul 18, 2006 3:37 pm
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.

Posted: Fri Jul 28, 2006 2:47 pm
by spyro
Looks cool! :D
I will try it with OpenGl and thanks for your help.

Posted: Fri Jul 28, 2006 3:55 pm
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;
}


Posted: Fri Jul 28, 2006 4:05 pm
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

Posted: Fri Jul 28, 2006 4:28 pm
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();

Posted: Fri Jul 28, 2006 4:50 pm
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