GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


UPDATED: example texture creation by baldurk
void Draw()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -6.0f);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);
    glBegin(GL_QUADS);
    {
        glColor3f(1.0f, 1.0f, 1.0f);
        glTexCoord2f(0.0f, 1.0f);glVertex3f(-1.0f,  1.0f, 0.0f);
        glTexCoord2f(1.0f, 1.0f);glVertex3f( 1.0f,  1.0f, 0.0f);
        glTexCoord2f(1.0f, 0.0f);glVertex3f( 1.0f, -1.0f, 0.0f);
        glTexCoord2f(0.0f, 0.0f);glVertex3f(-1.0f, -1.0f, 0.0f);
    }
    glEnd();
}

void Init()
{
#define SIZE 64

    float texarray[3 * SIZE * SIZE];

    for(int i=0; i < SIZE; i++)
    {
        for(int j=0; j < SIZE*3; j += 3) // notice you must stride by 3, to a 3*SIZE limit
                                         // otherwise you get problems. I think this was
                                         // what you're doing wrong.
        {
            // notice also you must multiply i*SIZE by 3, for each pixel.

            texarray[j + (i*SIZE*3)] = float(rand()) / float(RAND_MAX);
            texarray[j + (i*SIZE*3) + 1] = float(rand()) / float(RAND_MAX);
            texarray[j + (i*SIZE*3) + 2] = float(rand()) / float(RAND_MAX);
        }
    }

    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SIZE, SIZE, 0, GL_RGB, GL_FLOAT, texarray);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}