DX screen offset
BlitzMax Forums/BlitzMax Programming/DX screen offset
| ||
can anyone know how produce this function in directx? I have this OpenGL version, but it doesn't work on all computers I've come to notice.'Offsets the whole screen - used for a screen shake effect Function SetViewOffset(offsetx:Float,offsety:Float) Global Original_offsetx:Float'Variable to remember the current offset Global Original_offsety:Float'Variable to remember the current offset glMatrixMode GL_PROJECTION'Switch the matrix mode glTranslatef offsetx-Original_offsetx,offsety-Original_offsety,0'Translate the camera to the given offsets Original_offsetx = offsetx'Store the current offset Original_offsety = offsety'Store the current offset glMatrixMode GL_MODELVIEW'Switch the Matrix mode back glLoadIdentity'Reset End Function |
| ||
Any particular reason you wouldn't just use SetOrigin()? |
| ||
Now I feel stupid. :p totally forgot about that one. Here's another random question, to remove the need for a new thread: This is what I wrote to capture and return a blurred image of the game, for use as a background(I use it when the player pauses). It's really slow, and has a delay when the player pauses. Is there any easy way to speed it up? Or something similar to achieve this effect? 'return a blurred screenshot of the current backbuffer Function GetBlurredSS:TImage() Local hw:Float = GraphicsWidth() / 2 Local hh:Float = GraphicsHeight() / 2 'Take a screenshot of the game Local Screenshot:TPixmap = GrabPixmap(0, 0, 1024, 768) Local Ss:TImage = LoadImage(Screenshot) MidHandleImage(Ss) Cls'clear the backbuffer 'Repeatively draw the screenshot at various sizes to create a blur effect SetAlpha(.1) SetScale(.98, .98) DrawImage Ss, hw + 10, hh DrawImage Ss, hw - 10, hh DrawImage Ss, hw, hh + 10 DrawImage Ss, hw, hh - 10 DrawImage Ss, hw, hh SetScale(1, 1) SetAlpha(1) 'Capture this blurred screenshot into a new image Local bss:TImage = CreateImage(1024, 768) GrabImage(bss, 0, 0) Cls 'clear the backbuffer Return bss'return the blurred background screenshot End Function |
| ||
I don't have BlitzMax installed so I can't test this, but would it be faster to simply resize the grabbed pixmap to a much smaller size and draw that stretched over the whole screen? If you shrink it and stretch it, it will automatically be blurred quite a bit, assuming filtering is enabled for that image. |
| ||
That'd be less resource-hungry too. To maximise efficiency, grab the image as a pixmap, resize it to, say 256x256, convert to an image then use DrawImageRect to draw it over the whole screen. |
| ||
Can you give me a code example of the drawing/stretching? I'm not sure quite how to do that Also, a weird possibly bug: When compiled in debug mode, this function works fine, but when in non-debug mode, there is no image drawn, just a black screen behind the paused menu. |
| ||
Well I'm hopeless at reading other people's code, so I'll leave that for somebody who isn't. :) Drawing a stretched image... dead easy. DrawImageRect is one function I make quite a lot of use of. If you have an 800x600 image that you want to use as a background, resize it in Photoshop or whatever to 512x512 - obviously that'll lose the aspect ratio and distort a bit. But, it will load nicely into VRAM with no waste whatsoever, unlike if you just loaded an 800x600 image which would be internally resized to 1024x1024. So take your new 512x512 image, and draw it with DrawImageRect: DrawImageRect myImage,0,0,800,600 For your needs, instead of resizing in photoshop, you can grab the screen as a pixmap, then resize the pixmap to, say, 256x256 or whatever. Then convert it to an image. Then all you have to do is use the above line of code to draw it, making sure that the image handle is set to 0,0. |
| ||
That would work, only the effect is to capture the current game and put it into an image. so what's currently happening in the game is paused and blurred (that's what it looks like anyways.) So what i'm getting at is: how do you resize a pixmap? |
| ||
Is this what you want?Strict Graphics 800,600 'draw some stuff For Local n:Int = 1 To 500 SetColor Rand(0,255),Rand(0,255),Rand(0,255) DrawOval Rand(0,GraphicsWidth()),Rand(0,GraphicsHeight()),Rand(20,50),Rand(20,50) Next 'grab the screen Local px:TPixmap = CreatePixmap(GraphicsWidth(),GraphicsHeight(),PF_RGBA8888) px = GrabPixmap(0,0,GraphicsWidth(),GraphicsHeight()) 'resize it px = ResizePixmap(px,256,256) 'make an image Local myImage:TImage = LoadImage(px) SetImageHandle myImage,0,0 While Not AppTerminate() Cls DrawImageRect myImage,0,0,GraphicsWidth(),GraphicsHeight() Flip Wend |
| ||
Perfect, thanks GfK. Sometimes the answers are so obvious. How do I resize a pixmap? Oh ResizePixmap() |