OpenGl ES Texture Problems

Nibbie
Posts: 2
Joined: 2009.02
Post: #1
I am working on a game for the Iphone and I have made a perl script to take a 3d model from 3ds Max and turn it into a .h file so that openGl can read it and draw it just perfect I can draw anything that I need and render it to the Iphone I can make it move around the screen and do anything I want it to do but I can not get it to texture correctly I have been working on this for a week now and no matter what I do I can not get it to texture. Now I think its the way my perl script sets up the texture coordinates here is a example for my perl script making a simple box into a .h


Code:
#define cube1_H

const int num_cube1_indices  = 36;
const int num_cube1_vertices  = 8;




float cube1_vertices  [] = {
     -1.7633,-1.4493,0.0000,
     -1.7633,0.2899,0.0000,
     -0.0242,0.2899,0.0000,
     -0.0242,-1.4493,0.0000,
     -1.7633,-1.4493,2.1256,
     -0.0242,-1.4493,2.1256,
     -0.0242,0.2899,2.1256,
     -1.7633,0.2899,2.1256,
};





float cube1_Texture[] = {
    1.0000,0.0000,0.0000,
    1.0000,1.0000,0.0000,
    0.0000,1.0000,0.0000,
    0.0000,0.0000,0.0000,
};





short cube1_indices [] = {
    0,1,2,
    2,3,0,
    4,5,6,
    6,7,4,
    0,3,5,
    5,4,0,
    3,2,6,
    6,5,3,
    2,1,7,
    7,6,2,
    1,0,4,
    4,7,1,
};


And here is the code to load the cube1 file:
Code:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTranslatef(0.0f,0.0f,-8.0f);
    glRotatef(rquad, 0.0f, 1.0f, 0.0f);    
    glVertexPointer(3, GL_FLOAT, 0, cube1_vertices);
    glTexCoordPointer(3, GL_FLOAT, 0, cube1_Texture);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    
    
        for(int i = 0; i < num_cube1_indices; i += 3)
    {
        
        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, &cube1_indices[i]);
    }

And here is what I'm using to add the texture:



Code:
spriteImage = [UIImage imageNamed:@"anypic.png"].CGImage;
        width = CGImageGetWidth(spriteImage);
    height = CGImageGetHeight(spriteImage);
        if(spriteImage) {
        
        spriteData = (GLubyte *) malloc(width * height * 4);
        
        spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
        
        CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
        
        CGContextRelease(spriteContext);
        
        
        glGenTextures(1, &spriteTexture);
    
        glBindTexture(GL_TEXTURE_2D, spriteTexture);

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
    
        free(spriteData);
        

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
    
        glEnable(GL_TEXTURE_2D);
    
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    
        glEnable(GL_BLEND);
    }

Now all this will draw a cube and texture the top and bottom just fine but the rest of it is just a blur of colors. Now if anyone out there can help me get my perl script or if it something in the loading and texture code fixed then I will release the perl script for every one to have and use as the see fit. I have used the perl script to draw and load all kinds of 3d models from animals to people they all render perfectly except the textures this would be a great little 3ds max script if we can get the texturing problems fix.
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.03
Post: #2
i think i know what's causing the problems for you (and this is an answer to your older post as well).

you will need to duplicate your vectors for each surface (e.g. 24 vectors for a cube and not 8).

at first you may think that this is a hack-workaround, but it's not.. it's quite standard.

good luck! and please do let us know when you're done with that script; it sounds quite useful.

i've subscribed to this thread, so please let me know if i was of any help!
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.03
Post: #3
in case you're not quite satisfied with "the answer" involving duplicating vertices, here's some more info for a bit of peace of mind knowing that you're not doing things the wrong way:

http://iphonedevelopment.blogspot.com/20...oject.html

in particular, read the comments up to "Dec 31, 2008 12:20 PM"
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.03
Post: #4
oh, i guess my original post never went up in the first place..?

whatever, my second reply has enough information to answer your question too Grin
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #5
devnote Wrote:oh, i guess my original post never went up in the first place..?

Yes. Right. We have to approve the first few posts of new members to filter out spammers. Yes, it is very annoying, sorry about that. Welcome to iDevGames Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  opengl es strange 16bit texture scale problem spuckfunkel 6 9,538 Aug 14, 2011 10:44 PM
Last Post: headkaze
  Performance problems with render to texture method mbw234 6 5,263 Jun 25, 2010 01:47 AM
Last Post: Jamie W
  Perfomance (FPS) problems in OpenGL and SDL. Help. riruilo 12 5,633 Oct 15, 2009 06:58 PM
Last Post: AnotherJake
  Increasing brightness of texture in OpenGL dsedov 3 6,033 Jul 29, 2009 03:00 PM
Last Post: arekkusu
  how to draw to OpenGL texture Gillissie 7 7,167 Apr 24, 2009 06:35 AM
Last Post: AnotherJake