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.
Related
I am using three.js and created a basic scene with a few meshses rendered with some basic lighting . My torus geometry was previously pointy with few polygons but I was able to smooth it out by adding more segments but now I would like to straighten the lines out in my cube. They seem jaggy. In the pic I am including my render on the left seems a lot jaggier then the example I am following on the right. I have even set width and height segments to very large values (200). Any Ideas why the aliasing/jagginess?My render on left, example on right
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
I'm working on a THREE.js scene that I'd like to render with a pixelated effect. To do so, I'm using renderer.setPixelRatio(...) to draw the scene at a low resolution, which works fine. The problem is that the result seems to be antialiased, maybe even by the canvas' WebGL context.
In the Canvas 2d drawing api, one can set canvas.context.imageSmoothingEnabled = false; to ensure that low-resolution scenes are drawn with a crisp pixelated effect. I tried using this parameter on my renderer.context, with no effect. Is there some other way around this?
Thanks!
This can be done with CSS stylesheets. Just add this line to the canvas style:
canvas {
image-rendering: pixelated;
}
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.
(sorry for my bad english)
I'm using Three.js to create a panorama. I would like to know if it is possible to get the color of a texture which I clicked on?
For that, I already have created a sphere and I can get the 3D coordinates on the sphere where I clicked (using, raycaster, projection,...).
The texture on the sphere is a ".png" with transparency. The area I would like to detect is colored :
Could you help me?