OpenGL function to render RGBA values - opengl-es-2.0

I have RGBA values for a frame in a buffer. How do I draw the frame on the screen using opengl? Which function do I have to use? I'm using opengl-es 2.0.
gldrawpixels() is not available in iOS glKit.

Use texture. glTexImage2D is probably available.
Then use this texture on full-screen quad.
That will involve some shader coding, when you could additionally process your colour data.

Related

How many primitives can I draw using Canvas in Android with Hardware Acceleration Layer enabled?

Is there hardware limitation to draw Rect, Line, Point etc per frame? I know Android uses a texture mask to draw a shape but no other info exists.

OpenGL ES 2.0: attach smaller texture to framebuffer

I have implemented bloom post process effect in my game for Android using render to texture and proper shaders. It works, but the performance hit is unacceptable. So I thought that I could render the scene to smaller texture and then stretch the texture to fullscreen. The trouble is that when I attach a texture that is smaller than the viewport to the off screen framebuffer, the scene is cropped. The image below illustrates the issue:
Is there any way I could "map" the attached texture to the framebuffer somehow, so the whole viewport gets rendered to it? I could probably modify the projection matrix to achieve the goal, but that would complicate my code and I would rather avoid it.
I think you can do that by simply changing the Viewport to match the texture dimensions before you do the render to texture, then set the viewport back to the dimensions of the View before you render to the framebuffer. There should be no significant performance loss because you will be calling glViewport() twice as often.
Your suggestion about scaling the projection matrix should also work.

Cropping Using OpenGL ES 2.0 iOS (vs. using Core Image)

I'm having difficulties finding any documentation about cropping images using OpenGL ES on the iPhone or iPad.
Specifically, I am capturing video frames at a mildly rapid pace (20 FPS), and need something quick that will crop an image. Is it feasible to use OpenGL here? If so, will it perform faster than cropping using Core Image and its associated methods?
It seems that using Core Image methods, I can't achieve faster than about 10-12 FPS output, and I'm looking for a way to hit 20. Any suggestions or pointers to usage of OpenGL for this?
Obviously, using OpenGl ES will be faster than Core Image Framework. Cropping image will be done by set Texture Coordinate, in generally, Texture Coordinate always like this,
{
0.0f,1.0f,
1.0f,1.0f,
0.0f,0.0f,
1.0f.0.0f
}
The whole image will be drawed with Texture Coordinate above. If you just want upper right part of a image, you can set Texture Coordinate like this,
{
0.5f,1.0f,
1.0f,1.0f,
0.5f,0.5f,
1.0f.0.5f
}
This will get a quater of the whole image at upper right. You never forget that the Coordinate origin of OpenGl ES is at the lower left corner

Using WebGL or OpenGL ES 2, how do I render the contents of an RBO onscreen?

Using WebGL (which is constrained to the OpenGL ES 2 API), I am successfully rendering to texture and then displaying that texture onscreen. Because it is a texture, it is not being antialiased. If I were rendering to an RBO and then displaying that onscreen, I would be able to take advantage of AA.
My render target setup looks like this:
Create FBO
Bind FBO
Create texture (to be rendered to)
Create and bind depth buffer as RBO
Attach texture and RBO to FBO
And my rendering update loop looks like this:
Render the scene to the FBO created in step #2 above
Render a screen aligned quad with the texture created in step #3 above
With desktop OpenGL, I would call glBlitFramebuffer() instead of drawing the screen aligned quad.
How do I render my scene with antialiasing? Do I need to replace the texture with an RBO? If so, what calls do I use to bind the RBO to draw a screen-aligned quad?
You cannot blit the contents of an RBO to screen in WebGL unless you perform a readback and re-upload to texture to blit, which is rather slow.
WebGL has no support for MSAA on FBOs in any form (neither as RBO nor as RTT).
You can implement your own antialiasing in a variety of ways.
Render at 2:2 size and scale down (google maps with webgl does this)
Render at 1:1 size, run a sobel or laplace edge detection on color and depth, and run a bilateral gaussian blur using edge strength as weight (I've used this technique in some of my demos, it works well, http://codeflow.org/entries/2011/apr/11/advanced-webgl-part-1/ )
Use the morphological antialiasing recipe from GPU Pro 2 (I've yet to try that)

Quartz 2D animating text?

i have to animate text around a circle. The text will also scale up/down. Whats the best approach to accomplish this? (i am using Quartz 2D)
My approach is:
-- Calculate point using sin and cos methods.
-- Move Pen there and draw text with alpha and size.
-- Clear the screen
-- Calculate next point using sin and cos methods.
-- Move pen there and draw text with alpha and size.
-- clear the screen
so on...
any better way?
If you're targeting iPhone OS ≥3.2, use CATextLayer.
Otherwise, you could create a UILabel and modify its transformation value, or control a CALayer directly.
If you're constrained to Core Graphics the method your described is the best already, but CG is not an animation framework. You should use Core Animations for UI animations.