Memory to Max2D BackBuffer

BlitzMax Forums/BlitzMax Programming/Memory to Max2D BackBuffer

RustyKristi(Posted 2016) [#1]
I'm trying some experiment and I would like to know how do I transfer raw image data to Max2D's back buffer in OpenGL/GL2. I got some tips from previous threads to use BackBuffer pointers.

I'm using EXTERN on this one for the c/c++ loading part where the image data will be coming from. This is sort of loading an image from file.

File -> Memory -> BackBuffer (GrabPixmap??)

Related links

This is the variables and setup for the C++ side..

unsigned char* ImageData;
unsigned long NumberOfBytes = Width * Height * BytesPerPixel;
ImageData = new unsigned char[NumberOfBytes];



thanks.


col(Posted 2016) [#2]
Sounds like youre making a streaming texture system? Transferring TO the backbuffer is usually done via textures and polygons going through the gpu pipeline, which is exactly what Max2D does already :p

I'm not too sure on the GL implementation as I'm well into DirectX myself but I guess you could ignore Max2D and create the texture handle/id ( or 'name' as OpenGL call it ) yourself using the OpenGL commands ( they are directly exposed as functions via Import Pub.OpenGL ). You can then setup up your own rendering system and 'upload' the cpu side texture data to the gpu texture via ( I believe ) glBindTexture and glTexSubImage2D.


RustyKristi(Posted 2016) [#3]
Thanks col! I will take note on that glBindTexture and glTexSubImage2D


Sounds like youre making a streaming texture system?


Nothing that complicated or interesting, just getting familiarize with external libs, Max2D and Image stuff. :-)


Kryzon(Posted 2016) [#4]
There's DrawPixmap, it does exactly that, plot a TPixmap directly to the active framebuffer (it's the backbuffer by default).

The function source for the GL and D3D drivers:

- https://github.com/maxmods/brl.mod/blob/master/glmax2d.mod/glmax2d.bmx#L484

- https://github.com/maxmods/brl.mod/blob/f1b5e6c115c30ba3a07f118ee6e8405a4340f77a/d3d9max2d.mod/d3d9max2d.bmx#L545


RustyKristi(Posted 2016) [#5]
thanks Kryzon. where does the image data coming from? My project needs to transfer from memory to GL

My hint is the TPixmap variable to transfer it to. So I'm wondering how do you get the source to that TPixmap variable.

This is the variables and setup for the C++ side..

unsigned char* ImageData;
unsigned long NumberOfBytes = Width * Height * BytesPerPixel;
ImageData = new unsigned char[NumberOfBytes];


EDIT: Updated post to show the above setup


TomToad(Posted 2016) [#6]
Use CreateStaticPixmap(ImageData,Width,Height,Width*BytesPerPixel,PF_RGBA8888)

You will need to replace PF_RGBA8888 with the actual data format used by your image.


RustyKristi(Posted 2016) [#7]
Thanks Tom Toad! I'm not sure about the format though but I have the option to use TGA/PNG and the image is only computed and rendered in memory.

I will try and confirm that later on or maybe I should start with greyscale images?


Kryzon(Posted 2016) [#8]
It might be faster to just try different pixmap formats on the BlitzMax end until the image looks right.
If you really needed to know the pixel format that your C++ code is outputting, you could write a half-red pixel (128, or 7f in hex) with maximum alpha (255, or ff), then read that pixel from that imageData buffer and see what bytes have those specific values, then you can find out what the other bytes represent.

Note that DrawPixmap is a 'blit' operation: it overwrites the pixels in the backbuffer with those of the pixmap. There's no blending.
If you want blending you'll have to load a TImage from that TPixmap and use DrawImage with the Max2D blend modes, like col mentioned in post above.


skidracer(Posted 2016) [#9]
I recommend doing everything in 32 bit format mapping one int per pixel makes for faster basic operations.

Here is a small demo that involves drawing stuff using raw memory pointers.

[ Edit ] now features bleed and blend operators.




RustyKristi(Posted 2016) [#10]
Thanks simonarmstrong, appreciate this example. I think I'm getting a handle on it and I should try exposing the c functions and let you guys know if I ran into problems.