C ++ - 在一个数组指针的地方多张图片 [英] C++ - place multiple images in an array pointer

查看:174
本文介绍了C ++ - 在一个数组指针的地方多张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图读取存储在磁盘上到使用土壤库中的数组指针十张图片。我想渲染,然后用3D纹理在OpenGL中得到的数据。

在code我写的从磁盘读取图像,并将其储存在一个缓冲区抛出了访问冲突读取位置00000000 错误。

这是利用土壤多个图像存储到一个数组指针的正确方法吗?

 无符号字符* TEX;
INT imSize =高*宽;无符号字符* BUFF =新的无符号字符[H * W *片]的for(int i = 1; I< = 10;我++)
{
    对于(INT J = 0; J< imSize; J ++)
    {
        如果(ⅰ== 1)
        {
            TEX =(无符号字符*)SOIL_load_OGL_texture(数据/ PA_170090.png
                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);            BUFF [((I-1)* imSize)+ J] = TEX [J]。 }        如果(ⅰ== 2)
        {TEX =(无符号字符*)SOIL_load_OGL_texture(数据/ PA_170091.png
                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
            BUFF [(I-1)* imSize + J] = TEX [J]。 }        如果(我== 3)
        {TEX =(无符号字符*)SOIL_load_OGL_texture(数据/ PA_170092.png
                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);
            BUFF [(I-1)* imSize + J] = TEX [J];}        ....
        .... //多达10张图像    }
}


解决方案

这似乎 SOIL_load_OGL_texture ,没有返回任何缓冲。相反,它返回一个ID(类型 GLuint ,这是 unsigned int类型)。如果失败,该ID将是零。你是整数值转换为一个指针解引用它,这会导致访问冲突。

I have been trying to read ten images stored on the disk into an array pointer using the SOIL library. I would like to then render the resulting data in OpenGL using 3D textures.

The code I wrote to read images from the disk and store them in a buffer throws up Access violation reading location 0x00000000 errors.

Is this the right way of storing multiple images using SOIL into an array pointer?

unsigned char *tex;
int imSize = h*w;

unsigned char *buff = new unsigned char[h * w * slices];

for(int i = 1; i<=10; i++)
{
    for(int j = 0; j<imSize; j++)
    { 
        if (i==1)
        {   
            tex = (unsigned char*) SOIL_load_OGL_texture("Data/PA_170090.png",
                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_INVERT_Y);

            buff[((i-1)*imSize) + j] = tex[j]; }

        if (i==2)
        {   tex = (unsigned char*)SOIL_load_OGL_texture("Data/PA_170091.png",
                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,  SOIL_FLAG_INVERT_Y);
            buff[(i-1)*imSize + j] =  tex[j]; }

        if (i==3)
        {   tex = (unsigned char*)SOIL_load_OGL_texture("Data/PA_170092.png",
                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,  SOIL_FLAG_INVERT_Y);
            buff[(i-1)*imSize + j] =  tex[j];}

        ....
        .... // up to 10 images

    }
}

解决方案

It seems SOIL_load_OGL_texture, is not returning any buffer. Instead, it returns an Id (of type GLuint , which is unsigned int). If the function fails, the id will be zero. You are casting that integer value to a pointer and dereferencing it, which results in access violation.

这篇关于C ++ - 在一个数组指针的地方多张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆