[.net] Problem drawing pixels

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi there! I wrote an SDL wrapper, and I would like to add output to a windows forms controls to it. But it won't work... First, there is the ControlSurface class, which inherrits from a basic Surface class, which also provides an abstract Update() method that serves for swapping buffers / redrawing, whatever the inherriting class wants. The Surface class also has an indexer that takes X, Y and returns a Color structure, representing the color. Here is the relevant ControlSurface class code:
public class ControlSurface : Surface
{
Control destControl;
Bitmap  backBuffer;

void controlPaint(object Sender, PaintEventArgs Args)
{
for(int y=0; y<size.Height; y++)
for(int x=0; x<size.Width; x++)
backBuffer.SetPixel(x, y, this[x, y]);

Args.Graphics.DrawImageUnscaled(backBuffer, 0, 0);

MessageBox.Show("Drawn!");
}

public ControlSurface(Control Control, Size Size)
{
surface = Sdl.SDL_CreateRGBSurface((int)Sdl.Video.SWSurface, Size.Width,
Size.Height, 32, 0x000000ff,	0x0000ff00, 0x00ff0000, 0);

backBuffer = new Bitmap(Size.Width, Size.Height);

destControl       = Control;
destControl.Paint += new PaintEventHandler(controlPaint);

MessageBox.Show("Initialized!");
}

public override void Update()
{
destControl.Invalidate();

MessageBox.Show("Updated!");
}
}


Note the MessageBoxes that I put in for debugging. Now I wrote a test program that has a Panel object, with that nice tooltip-yellow color as background. I create a ControlSurface instance, load a new image with the Surface(filename) constructor, and try to draw it:
public class MainForm : System.Windows.Forms.Form
{
...

ControlSurface display;
Surface        surface;

public MainForm()
{
InitializeComponent();
}

public static void Main(string[] args)
{
Application.Run(new MainForm());
}

{
dialog.ShowDialog();
if(dialog.FileName=="")
Application.Exit();

display = new ControlSurface(panel, panel.Size);
surface = new Surface(dialog.FileName);

surface.Blit(display, new Point(0, 0));
display.Update();
}
}


All the messageboxes show up, I don't get any loading errors from the Surface class, but the panel stays yellow. What could be wrong? Thanks beforehand!

Share on other sites
In Mono's CVS - http://www.mono-project.com/contributing/anoncvs.html - there is a fully complete binding for SDL called Tao.Sdl if you can't ever figure out what your current problem is and would rather just use another binding.

Share on other sites
I actually wrote my own binding, but it is not a 1-1 wrapper to SDL, but more a kind of a game library/engine, having classes such as sprites. But the library is primary built on top of SDL.NET, which is now Tao.Sdl of I understood it right. The get pixel code the same as the SDL.NET version.

The weird thing is that nothing is drawn at all - I mean, if something was wrong with the Color return value, you would either get one color or all kind of different colors, but now, really -nothing- happens. That's the problem. It seems like the resulting pixels are actually never drawn.

Share on other sites
To rule out the possibility of a broken library, I commented the get-the-color part out and changed it to Color.Green. Now, only using SWF, the bitmap should be filled with green pixels. But, it isn't. Any ideas?

void controlPaint(object Sender, PaintEventArgs Args){	for(int y=0; y<size.Height; y++)		for(int x=0; x<size.Width; x++)			backBuffer.SetPixel(x, y, /*this[x, y]*/Color.Green);		Args.Graphics.DrawImageUnscaled(backBuffer, 0, 0);		MessageBox.Show("Drawn!");}

Share on other sites
Ah, problem solved.

I found out that I forgot to call updateSurfaceSettings() in the constructor override, which is used to update the size properties and such in the class, which default to (0,0). Because of that, the for loop inmediately exited without getting/drawigng any pixels.

• 17
• 11
• 14
• 9
• 49
• Forum Statistics

• Total Topics
631393
• Total Posts
2999763
×