【问题标题】:color array handling with openGL使用 openGL 处理颜色数组
【发布时间】:2010-07-21 04:50:36
【问题描述】:

我正在使用 openGL 开发 ipad 应用程序。在我的应用程序中,基本上我正在绘制一个基本形状,即 3d 立方体,它可以根据用户的手指运动进行旋转。现在我被困在这个立方体的着色部分。我希望用户选择他选择的表面来为这个形状着色。

所以我想做的是......每次用户更改颜色时,我都会更改 glColorPointer() 的数组。但不能在这方面取得成功。这是我正在尝试做的示例

示例代码:

const GLubyte *cubeFace1;
const GLubyte *cubeFace2;

NSMutableArray *cubeFace1Arr = [[NSMutableArray alloc] initWithCapacity:20 ];
for ( i = 0; i < 16; i++) {
// black color. value of '255' will change according to the user's selection of color
    [cubeFace1Arr addObject: [NSNumber numberWithInt:255]];
}

NSMutableArray *cubeFace2Arr = [[NSMutableArray alloc] initWithCapacity:20 ];
for ( i = 0; i < 16; i++) {
// white color. value of '0' will change according to the user's selection of color
    [cubeFace2Arr addObject: [NSNumber numberWithInt:0]];
}

cubeFace1 = cubeFace1Arr; // warning: assignment from incompatible pointer type
cubeFace1 = cubeFace2Arr; // warning: assignment from incompatible pointer type


glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFace1);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFace2);

那么,我的基本问题是如何动态生成这个颜色数组?或者我如何删除这个waring..!!

在此先感谢您的帮助。

【问题讨论】:

    标签: objective-c iphone opengl-es nsarray ipad


    【解决方案1】:

    glColorPointer(与大多数 OpenGL 调用一样)需要纯 C 数组,而不是 Objective-C NSArray 对象。

    struct RGBAColor {
        GLubyte r, g, b, a;
    };
    
    struct RGBAColor cubeFace1[16];
    for( int i = 0; i < 16; i++ ) {
        cubeFace1[i].r = 255;
        cubeFace1[i].g = 255;
        cubeFace1[i].b = 255;
        cubeFace1[i].a = 255;
    }
    glColorPointer( 4, GL_UNSIGNED_BYTE, 0, cubeFace1 );
    

    我强烈建议您查看documentation

    【讨论】:

    • YO....得到了帮助......不完全是我需要的,但使用你的样本能够做我想做的事,是的,真的需要参考文档。谢谢你。
    • 您好 zpasternack :感谢您对先前答案的回复。如果你能再看看我的一个疑问,我会很高兴..!!祝你有美好的一天
    猜你喜欢
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多