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 06-23-2009, 07:04 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: currently AZ
Posts: 112
kingbombs is on a distinguished road
Send a message via MSN to kingbombs
Default Texture Problem OpenGL ES

So its weird, i draw the background with a Red color and then draw another area in Blue (a smaller square) then i draw a even smaller square in green.
All using the Color4f function to set there colors.
(everything is in 2D here!)

Now i have squares moving around inside the blue square.
The squares are white or black depending on there direction of movement, if i just use colors its fine but if i try and use textures to draw them the whole screen goes black and goes fine when the moving square switches color when it changes direction.

I thought it might be to do with them being the wrong pixel size, the moveable squares are 0.1 by 0.1. which i think in pixels is 24x16. I read somewhere they have to be atleast 32x32 not sure how try that is but they don't work at all when 24x16 or 16x24 but the problems happens when they are 32x32.

On the wrong computer to be able to post code at the moment.
This is ruffly my code, hopefully you can see the problem:
Code:
//code to make a square verticies
for (int i = 0; i < 5; i++)
{ //code to create individual moveable squares.
glPushMatrix()
// code to create dimensions and to move them depending on other stuff
glVertexPointer(2, GL_FLOAT, 0, moveableSquare);
if (moving == left)
glBindTexture(GL_TEXTURE_2D), textures[0];
else
glBindTexture(GL_TEXTURE_2D), textures[1];

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
}
Thats bassicly my code. Bare in mind above this part i am also drawing a background image and other squares and using glColor4f() to set there color rather than use an texture.

It seems to be either the first or last item placed that changes the whole screen color to black or to normal. The other colors change to one of the textures then change back to the last glColor4f() used for drawing other squares.

ALSO:
curious, what happens if the texture isn't of the right dimensions and you try to apply it to an object? what happens if the texture is to big and if its to small?

any help greatly appreciated!!

Last edited by kingbombs; 06-23-2009 at 07:21 PM.
kingbombs is offline   Reply With Quote
Old 06-25-2009, 04:19 PM   #2 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 16
Freakjob is on a distinguished road
Default

Your last question makes me wonder if you are using UV coordinates at all. (Kind of required for texturing..)
Freakjob is offline   Reply With Quote
Old 06-25-2009, 04:48 PM   #3 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

If you do this with texturing turned on:

Code:
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
You're drawing the first four points in your vertex array, using the first four points in your texture array. You must have set the texture point array somewhere. Search for glTexCoordPointer to find out where.

The range and magnitude of the vertices in moveableSquare[] has NO impact which part of the texture is used. Only the order of the points matters, and the texture coordinates. Let me explain using squares, because it's less confusing; I'm also going to assume a square is defined as two points (upper left, bottom right.) You'll have to work out how the triangles work, once you understand my squares.

Suppose I draw a square to the screen - the position and side doesn't matter. I also have a texture of a smiley face. If I set the texture coordinates for the upper-left and bottom-right as 0,0 and 1,1 then the entire smiley face will be drawn on the face of the square. Soak that in - the texture will be shrunk or stretched as appropriate, but it will appear only once on the face of the square. If I double the size of the square and rotate it, I see one smiley, rotated, at double the size.

If I set my texture coordinates as (0,0) and (0.5, 0.5) , then I will see one quarter of the smiley face - just the upper left corner and left eye. Sketch this out on a piece of paper if you need to.

With regards to tiling, if I set my coordinates as (0,0) and (2,2) , I will see four smileys on the face of the square (unless I turned clamping on). Two across, two down. There's your tiling.

This it probably very different than what's shown in many 3D programs, where one inch of texture covers one inch in world units, and repeats as necessary; but it makes much sense if you think about it. If you double the size of an object, you don't want the texture to start repeating on its own, do you? You want it to stretch to the object. And you don't want the texture to "flow" across the object as the object moves, right?

That's why the range of vertices don't matter. If I had to sum this up succinctly, I'd write "Point 1 in the vertex array is painted using point 1 from the texture array. Vertex point 2 is painted from texture point 2, etc. Everything else is interpolated."

Now, the squares you're drawing are made of two triangles, defined by four points, but the rules are the same. This stuff is in the OpenGL red book by the way, which is a very useful reference; even old (1.x) versions, which are available for under $10.

http://www.amazon.com/gp/redirect.ht...reative=390957
__________________

Free Games!

Last edited by smasher; 06-25-2009 at 04:50 PM.
smasher is offline   Reply With Quote
Old 06-25-2009, 07:57 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: currently AZ
Posts: 112
kingbombs is on a distinguished road
Send a message via MSN to kingbombs
Default

Thanks for the information it was good to hear and make sure i deffaintly understand what i have learnt over the last two days.

But i had forgot to reply and say i fixed the problem, it was simple the fact that i hadn't delcared all the textures i was loading.

Thanks for the information though!
kingbombs is offline   Reply With Quote
Old 09-14-2009, 02:01 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 8
ssakthivel is on a distinguished road
Default background color for particular texture

Hi,

I want to set the background color for particular texture data.Basically i have set my image data in texture. After it has been drawn i want only one texture to be blackcolor .How can i do that.

Please help me out...
ssakthivel 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: 407
7 members and 400 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

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