What's The Point ?
BlitzMax Forums/BlitzMax Beginners Area/What's The Point ?
| ||
I am interested in creating a PIXMAP that uses the following definition: What I am finding out however is no matter what value I put into it, it always comes out 100% opaque and white. What use is "pf_a8" then ? What would be a working code example where "pf_a8" is of benefit ? |
| ||
A pixmap is not an image. use something like: Drawimage(Loadimage(pic),0,0) |
| ||
Even worse results, the data gets garbled, GW. Try it. DrawImage LoadImage(Pic),0,0 |
| ||
When you look at the code in DrawPixmap it makes sense. It asks the OpenGL or Direct3D renderer for their own DrawPixmap function, which does some things. In case of OpenGL, for example, the function is this: https://github.com/maxmods/brl.mod/blob/21e9497433a4aadc3538062dd6181976204824ab/glmax2d.mod/glmax2d.bmx#L484 Method DrawPixmap( p:TPixmap,x,y ) Local blend=state_blend DisableTex SetBlend SOLIDBLEND '<------------- Here, it forces a solid blend. No transparency. Local t:TPixmap=p If t.format<>PF_RGBA8888 t=ConvertPixmap( t,PF_RGBA8888 ) '^^^ Line above, it converts to RGBA8888. 'Maybe some information is lost or converted 'in a way that isn't what you want. glPixelZoom 1,-1 glRasterPos2i 0,0 glBitmap 0,0,0,0,x,-y,Null glPixelStorei GL_UNPACK_ROW_LENGTH, t.pitch Shr 2 glDrawPixels t.width,t.height,GL_RGBA,GL_UNSIGNED_BYTE,t.pixels glPixelStorei GL_UNPACK_ROW_LENGTH,0 glPixelZoom 1,1 SetBlend blend End Method Here's how the pixmap conversion happens: https://github.com/maxmods/brl.mod/blob/21e9497433a4aadc3538062dd6181976204824ab/pixmap.mod/pixel.bmx#L73 Try creating an image out of that pf_a8 pixmap, then use SetBlend ALPHABLEND and draw the image. Alternatively, if you want an opaque image with grayscale opaque pixels, use format PF_I8, create an image from it and use solid blend. By looking at the conversion code, it seems that's how it should be used. |
| ||
The disabletex command is not recognized. And this line:Local t:TPixmap=pcrashes w Unable to convert from 'Int' to 'TPixmap.' |
| ||
You're not supposed to use that function dude, I posted it to illustrate what the Max2d module is doing internally. It's taken from the module source code and uses other internal functions. The last paragraph in my post has the answer, beginning with "try creating an image...". |
| ||
Well I did a bit more research on this Kryzon, the reason it's not working the way I want it to is - I need to have marked the SETGRAPHICSDRIVER() routine to be able to record ALPHA in addition to regular pixels. This will actually benefit a project I'm working on ATM. |
| ||
I'm pretty sure that the BACKBUFFER_ALPHA flag does not influence the blending at all, it just specifies that you want a backbuffer where pixels can be transparent (as if the game window had holes). Besides, according to the graphics source code, that flag is ignored with the Direct3D driver. With OpenGL it is used, but then Windows doesn't support backbuffers with alpha channel. D3D - https://github.com/maxmods/brl.mod/blob/master/dxgraphics.mod/d3d9graphics.bmx#L67 (Backbuffer format X8R8G8B8, the X means it doesn't use alpha, it only allocates space for it.) GL: - https://github.com/maxmods/brl.mod/blob/master/glgraphics.mod/glgraphics.win32.c#L69 (Using a PixelFormatDescriptor to hold the alpha setting) - https://msdn.microsoft.com/en-us/library/windows/desktop/dd368826(v=vs.85).aspx (The MSDN entry that specifies that alpha channels for the backbuffer are not supported). You really need to use SetBlend to control the blending. If you set alpha blending you can get the effect even when not using the _ALPHA flag. |
| ||
The reason it gets garbled is because the width is incorrect when accessing the pixels.Strict Graphics 640,480 SetBlend alphablend Local pic:TPixmap=CreatePixmap(320,240,pf_a8),i,j ClearPixels pic,128 For i=0 Until 64 For j=0 Until 64 pic.pixels[j+i*pic.Width]=192 Next Next DrawImage LoadImage(pic),0,0 Flip WaitKey |
| ||
Grable answered it ! (careless error on my part) And wow ! That's pretty cool, here is working model: Ahh ! That's lovely ! This has definite possibilities ... |