color array handling with openGL
I am developing an ipad app with openGL. In my app basically I am drawing a basic shape i.e 3d cube, which can rotate according to user's finger motion. Now I am stuck on coloring part of this cube. I want user to choose surfaces of his choice to color this shape.
So what I am trying to do is...I am changing the array for glColorPointer() everytime when user change color. But cant got success in that. Here is the sample what I am trying to do
sample code :
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);
开发者_开发知识库So, my basic problem is how I generate this color array dynamically? or how I remove this waring..!!
Thanks in advance and help appreciated.
glColorPointer (as with most OpenGL calls) want plain C arrays, not Objective-C NSArray objects.
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 );
I highly recommend checking out the documentation.
精彩评论