I want to create a 2D grid of rectangles in blackberry using OpenGL ES. How can I do it?
Related
I'm looking for a most efficient way of drawing a 2-dimensional background in metal. This requires rendering a textured rectangle.
The basic geometry example shows an example on how to draw a triangle. Is there an easy and non-bloated way to draw a rectangle (a polygon with 4 corners)?
The Basic Texturing sample draws a textured rectangle
Is it possible in OpenGL ES 2.0 to use GL_LINE_STRIP to draw a shape and then apply a texture to that shape ?
E.g if I draw a triangle can I then apply a triangle texture ?
GL_LINE_STRIP draws only lines. If you want polygons filled in (whether with color, lighting, or texturing), you need one of the solid polygon modes: GL_TRIANGLES, GL_TRIANGLE_STRIP, or GL_TRIANGLE_FAN.
If you want to both fill and stroke your polygons, you'll need two draw calls, one with each mode. And if you're using depth testing, you'll probably want to look into glPolygonOffset to avoid z-fighting.
I'm trying to load an image into a texture, then draw into the texture.
Am I right in thinking that to display a texture you always need an array of vertices and texture coordinates? So, to draw a square texture I would need to draw 2 triangles to make a square and attach the texture to them?
Yes, that's right. For a square texture, the alternative is to use point sprites with GL_POINTS.
I have a human model in an .OBJ file I want to display as a mesh with triangles. No textures. I want also to be able to move, scale, and rotate in 3D.
The first and working option is to project the vertices to 2D using the maths manually and then draw them with Quartz 2D. This works, for I know the underlying math concepts for perspective projection.
However I would like to use OpenGL ES for that method, but I am not sure how to draw the triangles.
For example, the code in - (void)drawRect:(CGRect)rect is:
glClearColor(1,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
GLKBaseEffect *effect = [[GLKBaseEffect alloc] init];
[effect prepareToDraw];
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
Now what? I have an array of vertex positions (3 floats per vertex) and an array of triangle indices, so I tried this:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, numVertices,pVertices);
glDrawElements(GL_TRIANGLES, numTriangles, GL_UNSIGNED_INT,pTriangles);
but this doesn't show anything. I saw from a sample the usage of glEnableVertexAttribArray(GLKVertexAttribPosition) and glDrawArrays but I 'm not sure how to use them.
I also understand that rendering a wireframe is not possible with ES? So I have to apply color attributes to the vertices. That's ok, but before that the triangles have to be displayed first.
The first thing I'd ask is: where are your vertices? OpenGL (ES) draws in a coordinate space that extends from (-1, -1, -1) to (1, 1, 1), so you probably want to transform your points with a projection matrix to get them into that space. To learn about projection matrices and more of the basics of OpenGL ES 2.0 on iOS, I'd suggest finding a book or a tutorial. This one's not bad, and here's another that's specific to GLKit.
Drawing with OpenGL in drawRect: is probably not something you want to be doing. If you're already using GLKit, why not use GLKView? There's good example code to get you started if you create a new Xcode project with the "OpenGL Game" template.
Once you get up to speed with GL you'll find that the function glPolygonMode typically used for wireframe drawing on desktop OpenGL doesn't exist in OpenGL ES. Depending on how your vertex data is organized, though, you might be able to get a decent wireframe with GL_LINES or GL_LINE_LOOP. Or since you're using GLKit, you can skip wireframe and set up some lights and shading pretty easily with GLKBaseEffect.
What is the best way to draw circles with OpenGL ES 2.0?
I am working on an iPad/iPhone project using cocos2d 2.0 (currently beta) which uses OpenGL ES 2.0 and shaders instead of OpenGL ES 1.0.
In my former projects I used that handy class ColoredCircleSprite that is included in the SneakyInput package. But now with OpenGL ES 2.0 that code is not working anymore and to be honest I am a little lost here in writing my own solution from scratch. I need a CCSprite subclass that draws smooth circles. (Perhaps with a little shadow shader...)
Should I build a rectangular shape in the vertex shader and then discard every pixel outside the circle radius in the fragment shader? Or should I build the circle vertices inside the vertex shader?
Are there any good tutorials about this topic on the net? As OpenGL-n00b I would appreciate every kind of help!
Use ccDrawCircle:
ccDrawCircle(CGPoint center, float radius, float angle,
NSUInteger segments, BOOL drawLineToCenter);
Increase the number of segments to make the circle smoother. Have a look at the implementation of ccDrawCircle in CCDrawingPrimitives.h if you want to learn from the code.