OpenGl ES Texture Problems

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

#define cube1_H

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

float cube1_vertices  [] = {

float cube1_Texture[] = {

short cube1_indices [] = {

And here is the code to load the cube1 file:
    glRotatef(rquad, 0.0f, 1.0f, 0.0f);    
    glVertexPointer(3, GL_FLOAT, 0, cube1_vertices);
    glTexCoordPointer(3, GL_FLOAT, 0, cube1_Texture);
        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:

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);
        glGenTextures(1, &spriteTexture);
        glBindTexture(GL_TEXTURE_2D, spriteTexture);

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

        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

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
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
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:

in particular, read the comments up to "Dec 31, 2008 12:20 PM"
Quote this message in a reply
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
Posts: 3,591
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 12,913 Aug 14, 2011 10:44 PM
Last Post: headkaze
  Performance problems with render to texture method mbw234 6 7,420 Jun 25, 2010 01:47 AM
Last Post: Jamie W
  Perfomance (FPS) problems in OpenGL and SDL. Help. riruilo 12 7,486 Oct 15, 2009 06:58 PM
Last Post: AnotherJake
  Increasing brightness of texture in OpenGL dsedov 3 8,185 Jul 29, 2009 03:00 PM
Last Post: arekkusu
  how to draw to OpenGL texture Gillissie 7 9,180 Apr 24, 2009 06:35 AM
Last Post: AnotherJake