Draw/get pixels in Mogre

Bady

24-03-2012 22:39:33

I would like to ask, is possible to draw a single pixel somehow (example i give coordinates, and color vaules or something like that)
My amother question is, Can I get informaiton about a pixel in the screen?
And how?

Thank you the answers.

zarfius

27-03-2012 13:04:03

There are a couple of ways to approach this. It really depends on why you want to do it? So my first response is...

Why do you want to draw a single pixel?

If your intention is to draw multiple single pixels, you'd probably be better off drawing them on a texture and then generating simple geometry to render the texture.
Another thought is to draw individial vertices as points, this will appear as single pixels but is not very good for doing multiple pixels close to each other.
A third thought is to make use of the particle system. This allows small "sprites" to be rendered and animated efficiently.
Is this for a 2D game, or a GUI or inside a 3D world or what?

Bady

27-03-2012 18:23:57

MY plan is:
I Scan the screen and if the previous/next pixel is not the same, then put there a pixel.


edit:
And i would like to make it real time.
Well, it Will be a special Graphic effect, if not make it my program too slow.
I think about Sprites, but i dont' know more tousand sprites maybe burden the video card/processor.

zarfius

28-03-2012 07:06:05

MY plan is:
I Scan the screen and if the previous/next pixel is not the same, then put there a pixel.

I've never tried anything like this, but my first thought would be 'render to texture'.
http://www.ogre3d.org/tikiwiki/Intermed ... to_texture

edit:
And i would like to make it real time.
Well, it Will be a special Graphic effect, if not make it my program too slow.
I think about Sprites, but i dont' know more tousand sprites maybe burden the video card/processor.

You might be surprised. Rendering sprites (when done correctly) could be much faster than any other method.

Graphics cards these days are particularly good at rendering many thousands of triangles. The main bottleneck to consider here is batches (material changes). So, what you could do is make a single texture (material) with lots of little rectangular sections and render each triangle (or pair of triangles) with different texture coordinates. Effectively splitting up the texture into lots of smaller textures but at the same time keeping your batch count down.

You'll probably also get many more answers if you try the main Ogre forums instead because there are many more users reading them. If they come up with a solution in C++ you can head back here and someone can help you convert it to C#.

Aralox

28-03-2012 13:05:26

There was a page in the manual that had a little tutorial on creating custom textures, but I cant for the life of me find it :S
The pages on Hardware pixel buffers should help though: http://www.ogre3d.org/docs/manual/manual_64.html#SEC293

Here is a simple function I wrote a while ago when learning about textures:
(It creates a 1x1 texture with a single colour. Some of the comments are directly copied from that manual page i cant find)

public static TexturePtr MakeTexture(System.Drawing.Color col)
{
//Use this for a System.Drawing.Color
uint intColor = (uint)col.ToArgb();

//Use this for a Mogre ColourValue
//uint intColor = col.GetAsARGB();

var texture = TextureManager.Singleton.CreateManual(
"img" + Guid.NewGuid().ToString(), ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
TextureType.TEX_TYPE_2D, 1, 1, 1, Mogre.PixelFormat.PF_A8R8G8B8);

HardwarePixelBufferSharedPtr buffer = texture.GetBuffer();

unsafe
{
/// Lock the buffer so we can write to it
buffer.Lock(HardwareBuffer.LockOptions.HBL_NORMAL);
PixelBox pixelBox = buffer.CurrentLock;

/// Update the contents of pb here
/// Image data starts at pb.data and has format pb.format
uint* data = (uint*)pixelBox.data;

uint height = pixelBox.box.Height;
uint width = pixelBox.box.Width;
uint pitch = pixelBox.rowPitch; // Skip between rows of image

for (uint y = 0; y < height; ++y)
{
for (uint x = 0; x < width; ++x)
{
data[pitch * y + x] = intColor;
}
}

/// Unlock the buffer again (frees it for use by the GPU)
buffer.Unlock();
}

return texture;
}


Hopefully that'll give you an idea of how to begin with texture manipulation. Good luck :)

Bady

03-04-2012 00:25:09

Thank you. :)
I will try it, and i will writing, when i have problems again :D

Beauty

17-04-2012 13:46:21

Hi Bady,

welcome to Mogre :D

a special Graphic effect
Ogre has a possibility to hook / interrupt the rendering process for applying custom.
It's useful for postrendering-effects. But I don't know details.
This is a general Ogre question, not Mogre specific.
So the best would be to ask this in the Ogre main forum again (if you still need it).
There are much more users than here. The chance for a good answer is rising a lot.

not make it my program too slow.
Then it should be shader based. (Compute only on GPU.)

A very useful looking page is the JaJDoo Shader Guide in the Ogre wiki.


It's also possible to create a pixel ("point") in 3D space (applied to a 3D coordinate).
The size is always 1 pixel, independent of the distance.
For this you can use the ManualObject class.
Much information about its usage I wrote on the ManualObject wiki page.

Well, this is not useful for your field of application. Just to let you know.