How to render a radial field in OpenGL?
-
How would I render a 2D radial field in OpenGL? I know I can render it pixel by pixel but I'm wondering if there are more efficient solutions? I don't mind if it requires OpenGL3+ functionality.
-
Answer:
How familiar are you with shaders? Because I'm thinking an easy-ish answer would be to render a quad and then write a fragment shader to color the quad based off of how far each pixel is from the center. Pseudocode: vertex shader: vec2 center = vec2((x1+x2)/2,(y1+y2)/2); //pass this to the fragment shader fragment shader: float dist = distance(pos,center); //"pos" is the interpolated position of the fragment. Its passed in from the vertex shader //Now that we have the distance between each fragment and the center, we can do all kinds of stuff: gl_fragcolor = vec4(1,1,1,dist) //Assuming you're drawing a unit square, this will make each pixel's transparency smoothly vary from 1 (right next to the center) to 0 (on the edce of the square) gl_fragcolor = vec4(dist, dist, dist, 1.0) //Vary each pixel's color from white to black //etc, etc Let me know if you need more detail
Jeroen Bollen at Stack Overflow Visit the source
Related Q & A:
- How do I enter a business field?Best solution by answers.yahoo.com
- How to get a good salary job in the medical field?Best solution by differentmedicalcareers.com
- What is a radial scratch?Best solution by Yahoo! Answers
- How to get a job in the medical field with no degree?Best solution by monster.com
- How to become a field agent?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.