Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2010, 08:43 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
axfo is on a distinguished road
Smile How to draw two or more rectangles in OpenGL ES 1.x

Hi!

I am new in OpenGL. Just started to play with drawing triangles and rectangles.
When I want to draw one rectangle I have to define 4 vertices.
Then I call:

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

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Everything is working and I can see the results in the simulator.

But how to draw to two or more separate rectangles which don't touch each other with one call to glDrawArrays?
Is it possible? When I add next vertices to the array and increment the count
it does not work.

Cheers
axfo
axfo is offline   Reply With Quote
Old 12-24-2010, 08:54 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 234
warmi is on a distinguished road
Default

Quote:
Originally Posted by axfo View Post
Hi!

I am new in OpenGL. Just started to play with drawing triangles and rectangles.
When I want to draw one rectangle I have to define 4 vertices.
Then I call:

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

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Everything is working and I can see the results in the simulator.

But how to draw to two or more separate rectangles which don't touch each other with one call to glDrawArrays?
Is it possible? When I add next vertices to the array and increment the count
it does not work.

Cheers
axfo
Use indices.

Your vertex array describes vertices ( points) while your index array would describe their relationships ( essentially triangles)
warmi is offline   Reply With Quote
Old 12-24-2010, 01:37 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
axfo is on a distinguished road
Default

Quote:
Originally Posted by warmi View Post
Use indices.

Your vertex array describes vertices ( points) while your index array would describe their relationships ( essentially triangles)
Thanks a lot.
Just did it and works fine.
Instead of glDrawArrays I used glDrawElements.

One more question?
Is it possible to mix drawing rectangles with drawing textures in one function call?

Cheers
AF
axfo is offline   Reply With Quote
Old 08-17-2011, 10:20 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 1
martiin59 is on a distinguished road
Default

Quote:
Originally Posted by axfo View Post
Thanks a lot.
Just did it and works fine.
Instead of glDrawArrays I used glDrawElements.

One more question?
Is it possible to mix drawing rectangles with drawing textures in one function call?

Cheers
AF
How to detect collisions based on pixels, of any other color than black, which is the air.
martiin59 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 415
12 members and 403 guests
7twenty7, chemistry, ChrisYates, djohnson, gmarro, hussain1982, Kirkout, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0