Vulkan - draw texture directly without vertices and shaders - graphics

Is it possible to draw texture (if it is with correct width, height and pixel format) directly to frame buffer without using vertices and shaders in Vulkan?

You can do a vkCmdCopyImage to copy from your vkImage to a swapchain's vkImage provided the vkSurface supports being a TRANSFER_DST as by the supportedUsageFlags field from the result of vkGetPhysicalDeviceSurfaceCapabilitiesKHR.
Otherwise you need to do a fullscreen render and grab the color data from the input image as a sampled texture or input attachment.

Related

Pygame - Changing shape/moving Collision Rect. for the sprite

I have a pygame sprite animation where the position and shape of the sprite changes throughout a certain animation sequence (eg. - attack). How do I adjust the sprite's rect for collisions?
My Image: in one part of the animation, my sprite is at the center of a png image file (96x64 pixels). In another part of the animation, my sprite is near the right side of the png image file (96x64 pixels). In another part of the animation, the sprite changes shape (caused by sword movement). Etc.
Do I have to do some math and calculation to adjust the collision rect. of the sprite each frame of the animation or is there an easier method?
I am new to pygame so I'm not sure of all the different features and am not sure where to begin with creating the different rects. for each frame.
PS. I am using a ready-made sprite I found online - each frame is 96x64 pixels in dimension
Frame 1, 11, 22:
It's been a while since I've worked with Pygame but I believe you can use a pygame.mask object. A mask is basically an object with the precise outline of the foreground of an image. It takes considerably more computation power but if you only create a mask for the one main character then it should be okay.
You can create a mask from the image:
myMask = pygame.mask(myImage)
Then you can either use its rect or create a new surface to use:
myRect = myMask.get_rect() # Returns the pygame.Rect object that conatains mask, or:
mySurface - myMask.to_surface() # Returns a pygame.Surface object of the mask
Hope this helps, my info is from:
https://www.pygame.org/docs/ref/mask.html

CorelDraw does not preserve pattern fill when exporting to SVG

I have a big vector picture in CorelDraw X7. I made a small square bitmap texture and converted it to fill pattern and then filled a large figure with it. I expect that when I export to SVG the bitmap ends up filled as the SVG pattern tag but instead it is copied many times to fit. It looks fine but the problem is its large size over 1MB due to the texture being copied many times. How do I fill and export to SVG a bitmap texture making it size-efficient?

color blending with GDI+

I am refering to a older question saying color blending with GDI+
Using GDI+ with Windows Forms, I want to be able to draw with a pen and blend color based on the destination pixel color.
For example, if I draw a line and it passes over black pixels, I want it to be a lighter color (like white for example) so that it's visible. When that same line passes over white pixels, it should be a darker color (black for example) so that it's still clearly visible.
the answers says to use a color matrix for transformation
so i started implementing it..
My image is present in raw data format in rgb48
Gdiplus::Bitmap image(input.width,input.height,input.width*6,PixelFormat48bppRGB,(unsigned char*)rgb48);
Gdiplus::Image *images= image.GetThumbnailImage(input.width,input.height);
Gdiplus::TextureBrush brush(images);
Gdiplus::Pen pen(&brush);
Gdiplus::ColorMatrix matrix={
-1.0f,0.0f,0.0f,0.0f,0.0f,
0.0f,-1.0f,0.0f,0.0f,0.0f,
0.0f,0.0f,-1.0f,0.0f,0.0f,
0.0f,0.0f,0.0f,1.0f,0.0f,
1.0f,1.0f,1.0f,0.0f,1.0f,
};
Gdiplus::Graphics gfx(&image1);
Gdiplus::ImageAttributes imageAttr;
imageAttr.SetColorMatrix(&matrix);
gfx.DrawImage(images,Gdiplus::Rect(0,0,input.width,input.height),0,0,1024,1024,Gdiplus::UnitPixel,&imageAttr);
I am not getting what i expect..Can some one help me in finding the mistake i m doing.
You can use the alpha component of a color to specify transparency, so that colors can be combined. However, if you want the combination to be something other than the alpha blend, you must draw the pixels yourself. You could first draw into a transparent bitmap, then render that onto the destination pixel by pixel.

How to print a string over a 3d scene in OpenGL

i need some help to print a string over a opengl 3d scene.
I have some problems using modelview matrix and projection matrix. As I understand, projection matrix is used for the scene setup, and modelview matrix is used for drawing and transformating an object in the scene. So, to paint something over a 3D scene I understand that the next procedure most be done:
setup projection matrix for 3d scene
setup modelview matrix for 3d scene
draw opengl stuff
setup projection matrix for 2d overlay
setup modelview matrix for 2d overlay
draw opengl stuff for hud
Is this the right procedure?
For 2D rendering you can think of the projection matrix as you canvas and the movelview as the position of your text. You want to setup an orthogonal projection like this:
glOrtho(0.0F, windowWidth, 0.0F, windowHeight, -1.0F, 1.0F);
With this projection each unit means one pixel (glTranslate2f(120.0, 100.0) would position your text at pixel (120, 100). This projection maps the (0,0) in the bottom-left corner of your screen. If you want to map it to top-left corner you can do:
glOrtho(0.0F, windowWidth, windowHeight, 0.0F, -1.0F, 1.0F);
As of how to render text, OpenGL doesn't support it by default which means either you have to create a font rendering lib or using a existing one. Before doing that, you'll need to have in mind your needs for text rendering: Is is flat or 3D? It will be static or transformed(scaled, rotated), etc.
Here you can find a survey on opengl text rendering techniques with pros and cons and libs:
http://www.opengl.org/archives/resources/features/fontsurvey/
I started using FTGL to render TTF font, but the lib was destroying my game performance. So I decided to implement my own font lib and went with texture fonts, which are not better than TTF, but it was ok for my needs.
I used this program: http://www.angelcode.com/products/bmfont/
It takes a TTF font and exports a texture and a file descriptor containing each letter position, size and padding in the texture that you will use to render.
Hope that helps.

How to draw a transparent rectangle?

How to draw a transparent rectangle in j2me?
Transparency is supported only in immutable images, i.e. images loaded from files. So you can create appropriate image. Or create transparency via filling its transparency parts with background color.
Nokia has some functions that will allow you to draw transparent rects and polygons
http://www.developer.nokia.com/Resources/Library/Java/_zip/GUID-237420DE-CCBE-4A74-A129-572E0708D428/com/nokia/mid/ui/DirectGraphics.html
However if you want it to be a generic solution you should create a transparent image in code and draw it in the appropriate position. Create a int array with size = width*height then fill it with the required color (for example 0x550000ff for semi transparent blue) and create the image using Image.createRGBImage (and setting the last parameter to true).
int[] tmpArray = new int[width*height];
for(int i=tmpArray.length;i--!=0;)
tmpArray[i] = 0x550000ff;
Image transparentRectImg = Image.createRGBImage(tmpArray,width,height,true);
Also don't forget that some old j2me devices do not support alpha transparency even in images.

Resources