From the docs i understood i need to do the following:
char rgb array -> wxImage -> wxBitmap -> Display
My source data is a size*size float based rgb array (named: colarr). So
first i convert it to an unsigned char based rgb array (named: d).
Then i create a wxImage and use SetData to make it point to the char array.
The problem is that this crashes: wxbmp = wxBitmap(wximg, -1); (access
violation)
wximg.Ok() returns true so it should be possible to convert it to a
wxBitmap and display it.
Any help is greatly appreciated :)
// -------- code ----------
void texture::tctextowximage()
{
d= (unsigned char *) malloc (size*size*channels);
// doesn't use new :)
int c=0;
for (unsigned int x=0; x<size; x++)
{
for (unsigned int y=0; y<size; y++)
{
// get float triplet (r,g,b)
unsigned char r=(unsigned char) (colarr [c++]*255);
unsigned char g=(unsigned char) (colarr [c++]*255);
unsigned char b=(unsigned char) (colarr [c++]*255);
unsigned char a;
// write float triplet (r,g,b)
*d++=r;
*d++=g;
*d++=b;
if (channels==TC_RGBA) // atm this is not the case
{
a=(unsigned char) (colarr [c++]*255);
*d++=a;
}
}
}
// request a size*size wximg
wximg=wxImage(size,size);
// make it point to the rgb data adressed by d
wximg.SetData(d);
}
void texture::wximagetowxbitmap()
{
initted=true;
wxbmp = wxBitmap(wximg, -1); // <<<--- this crashes
}
// -------------------
> void texture::wximagetowxbitmap()
> {
> initted=true;
> wxbmp = wxBitmap(wximg, -1); // <<<--- this crashes
> }
So compile wxWidgets and your application in debug mode
and start debuggging. I personally have my glass bowl not at hand to
see whats happening there.
Come on, you have all the source...
regards,
gunnar
regards,
gunnar
>
> i would like to display a texture i have created in memory using
> wxBitmap (not read from disk).
>
> From the docs i understood i need to do the following:
> char rgb array -> wxImage -> wxBitmap -> Display
>
> My source data is a size*size float based rgb array (named: colarr).
> So first i convert it to an unsigned char based rgb array (named: d).
> Then i create a wxImage and use SetData to make it point to the char
> array.
>
> The problem is that this crashes: wxbmp = wxBitmap(wximg, -1); (access
> violation)
>
> wximg.Ok() returns true so it should be possible to convert it to a
> wxBitmap and display it.
>
> Any help is greatly appreciated :)
Don't increment d to the end of your malloc'ed array and then try and
use the same d to tell wxImage where your bytes are.
You need something like
p = d
Just after the malloc, and
wximg.SetData(p);
instead of wximg.SetData(d);
This is not really a wxWidgets problem.
Cheers,
drj
That was indeed the cause of the violation, thank you for pointing that out.
> This is not really a wxWidgets problem.
I realize this now, i just overlooked my bug several times and
afterwards i assumed i'm just using the wxBitmap constructer in a wrong way.
It is true that I should have checked things myself a bit longer before
I asked here.
> and start debuggging. I personally have my glass bowl not at hand to
> see whats happening there.
Well the cause was exactly what David Jones posted and well it seems
very obvious to me now. A glass bowl is certainly not necessary to find it.
> Come on, you have all the source...
I'm just getting started. Please be more gentle ;)
About your plattform/wxw version note: I forgot to mention it, in future
questions i will be more precise.