graphics
Generating a normal map from a height map?
Example GLSL code from my water surface rendering shader: #version 130 uniform sampler2D unit_wave noperspective in vec2 tex_coord; const vec2 size = vec2(2.0,0.0); const ivec3 off = ivec3(-1,0,1); vec4 wave = texture(unit_wave, tex_coord); float s11 = wave.x; float s01 = textureOffset(unit_wave, tex_coord, off.xy).x; float s21 = textureOffset(unit_wave, tex_coord, off.zy).x; float s10 = textureOffset(unit_wave, tex_coord, off.yx).x; … Read more
How exactly does OpenGL do perspectively correct linear interpolation?
The output of a vertex shader is a four component vector, vec4 gl_Position. From Section 13.6 Coordinate Transformations of core GL 4.4 spec: Clip coordinates for a vertex result from shader execution, which yields a vertex coordinate gl_Position. Perspective division on clip coordinates yields normalized device coordinates, followed by a viewport transformation (see section 13.6.1) … Read more
Haskell library for 2D drawing [closed]
Instead of picking individual libraries, I’ll have a go at a quick overview at all of them, as listed in the Graphics section on Hackage. Basic frameworks: OpenGL Part of the Haskell Platform Used for many small 2 and 3D games. Examples: lambdacube-engine, roguestar-gl, hpong, monadius, raincat, frag GTK cabal install cairo Used for high … Read more
Writing BMP image in pure c/c++ without other libraries
See if this works for you… In this code, I had 3 2-dimensional arrays, called red,green and blue. Each one was of size [width][height], and each element corresponded to a pixel – I hope this makes sense! FILE *f; unsigned char *img = NULL; int filesize = 54 + 3*w*h; //w is your image width, … Read more
How to convert a 3D point into 2D perspective projection?
The standard way to represent 2D/3D transformations nowadays is by using homogeneous coordinates. [x,y,w] for 2D, and [x,y,z,w] for 3D. Since you have three axes in 3D as well as translation, that information fits perfectly in a 4×4 transformation matrix. I will use column-major matrix notation in this explanation. All matrices are 4×4 unless noted … Read more
How can I set the matplotlib ‘backend’?
Your currently selected backend, ‘agg’ does not support show(). AGG backend is for writing to file, not for rendering in a window. See the backend FAQ at the matplotlib web site. ImportError: No module named _backend_gdk For the second error, maybe your matplotlib distribution is not compiled with GTK support, or you miss the PyGTK … Read more
Graphics on indexed image
Refering to this, it can be solved by creating a blank bitmap with the same dimensions and the correct PixelFormat and the draw on that bitmap. // The original bitmap with the wrong pixel format. // You can check the pixel format with originalBmp.PixelFormat Bitmap originalBmp = (Bitmap)Image.FromFile(“YourFileName.gif”); // Create a blank bitmap with the … Read more
How to best approximate a geometrical arc with a Bezier curve?
This is an 8-year-old question, but one that I recently struggled with, so I thought I’d share what I came up with. I spent a lot of time trying to use solution (9) from this article by Aleksas Riškus and couldn’t get any sensible numbers out of it until I did some Googling and learned … Read more