PDA

View Full Version : Creating 2 quads? - v simple question



MikeBaldock
12-09-2010, 07:25 AM
Hello,

I'm trying to learn how to use Open GL for an iPhone app. Just getting my head around the basics trying a few trial runs to get something going, and I'm stumped by a very simple problem!

using iOs 3.2 / Open Gl 1.1

In the apple provided OpenGl XCode Framework, they implement a simple program that draws a quad bouncing up and down according to sin(x)/2. As an experiment I'm trying to make 2 quads, but I don't know how to add the second???

What I've tried:
There's a class called ES1Renderer that initializes a 'context' to start drawing in, I've tried creating a new instance of ES12Renderer, and passing new parameters to the drawing method (making it bounce at sin(x)/3 for example)but that makes the whole screen blank.

I then tried making a second 'context' a context is:
[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]
and again this made the screen go blank.

I've also tried making a new set of squareVertices:


GLfloat squareVertices[] = {
-0.5f, -0.33f,
0.5f, -0.33f,
-0.5f, 0.33f,
0.5f, 0.33f,
};

GLfloat squareVertices2[] = {
-0.7f, -0.33f,
0.7f, -0.33f,
-0.7f, 0.33f,
0.7f, 0.33f,
};

glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);

glVertexPointer(2, GL_FLOAT, 0, squareVertices2);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);

but depending which way round I write this, I get one quad or the other, but not both.

This must be simple, but at which point do I start drawing 2 separate shapes?

MikeBaldock
12-09-2010, 07:26 AM
sorry about the double post, I got a message saying the database encountered a problem, so I clicked back, and posted the same message again.

randall
12-09-2010, 11:43 AM
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);

glDrawArrays(...);

glVertexPointer(2, GL_FLOAT, 0, squareVertices2);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);

glDrawArrays(...);

MikeBaldock
12-09-2010, 01:39 PM
Thank you! For some reason I was expecting the drawArrays method to only work for one context, getting there!