OpenGl glTexImage2D data

浪子不回头ぞ 提交于 2019-12-03 16:56:58
molostil

Hey Guys i solved my messed up texture reading ... i don't know what got into me but the initilization of my array was pure nonesense. here is the corrected code, i found out when trying to write a test texture:

// Allocate memory  
float * image = new float [width * height * 3 ];  
for( int i = 0; i < height; i++)  
{  
    for( int j = 0; j < width-1; j++)  
    {  
        fscanf( fDataFile, "%f,", &fData );  
        image[ 3 * (i * width + j) + 0 ] = fData;  
        image[ 3 * (i * width + j) + 1 ] = fData;  
        image[ 3 * (i * width + j) + 2 ] = fData;  
        //image[ 4 * i * j + 2 ] = 1.0f;  
    }  
    fscanf( fDataFile, "%f", &fData );  
    image[ 3 * (i * width + width-1) + 0 ] = fData;  
    image[ 3 * (i * width + width-1) + 1 ] = fData;  
    image[ 3 * (i * width + width-1) + 2 ] = fData;  
    //image[ 4 * i * width-1 + 2 ] = 1;  
}  

Furthermore it would work now independent of the internal format. GL_RGB, GL_RGBA, GL_RGB32F and GL_RGBA32F all work fine without changing the way i read my texture.

Thank you all!

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, &image[0]);

You should be using a floating-point internal format. For example, GL_RGB32F. That should be the third parameter.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!