0
我使用opengl調用在cocos2d中繪製圖像,但圖像以相反順序顯示並縮小比例,原始圖像大小爲320 * 480。我之前遇到過同樣的問題,那時候我曾經用cocos2d api v1的ccConfig文件中的0將CC_TEXTURE_NPOT_SUPPORT的值更改爲1,然後它正確顯示圖像,現在我正在創建新的cocos2d項目,我面臨同樣的問題,我遵循我使用的過程以前,但仍然圖像顯示相反的順序只有自己做錯了什麼是怎麼回事,我不知道......輸出的圖像以相反順序顯示並縮小爲一半尺寸cocos2d
截屏
這裏是我的代碼.....
代碼在初始化方法
if((self=[super init])) {
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
if (originalImage!=nil) {
originalImage=nil;
}
self.originalImage=[Utilities scaleAndRotateImage:[UIImage imageNamed:@"2.jpg"]];
texture2D = [[CCTexture2D alloc] initWithImage:originalImage];
NSLog(@"Width %f Height %f",texture2D.contentSize.width,texture2D.contentSize.height);
[self body_init];
self.isTouchEnabled = YES;
/*繪製下一幀動畫。 */
- (void)body_redraw {
int k;
int i, j;
if(mass == NULL) {
NSLog(@"mass is null");
return;
}
glBindTexture(GL_TEXTURE_2D, [texture2D name]);
k = 0;
for (i = 0; i < GRID_SIZE_X - 1; i++)
{
for (j = 0; j < GRID_SIZE_Y - 1; j++)
{
GLfloat vertices[]= {
mass[k].x[0],mass[k].x[1],mass[k].x[2],
mass[k + 1].x[0],mass[k + 1].x[1],mass[k + 1].x[2],
mass[k + GRID_SIZE_Y + 1].x[0],mass[k + GRID_SIZE_Y + 1].x[1],
mass[k + GRID_SIZE_Y + 1].x[2],
mass[k + GRID_SIZE_Y].x[0],mass[k + GRID_SIZE_Y].x[1],
mass[k + GRID_SIZE_Y].x[2]
};
GLfloat tex[]={
mass[k].t[0], mass[k].t[1],
mass[k + 1].t[0], mass[k + 1].t[1],
mass[k + GRID_SIZE_Y + 1].t[0], mass[k + GRID_SIZE_Y + 1].t[1],
mass[k + GRID_SIZE_Y].t[0], mass[k + GRID_SIZE_Y].t[1]
};
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, tex);
glDrawArrays(GL_TRIANGLE_FAN, 0,4);
k++;
}
k++;
}
}
- (void)body_init {
GLint width = texture2D.contentSizeInPixels.width;
GLint height = texture2D.contentSizeInPixels.height;
int i, j;
int k;
if (mass == NULL)
{
mass = (MASS *) malloc(sizeof(MASS)*GRID_SIZE_X*GRID_SIZE_Y);
if (mass == NULL)
{
fprintf(stderr, "body: Can't allocate memory.\n");
exit(-1);
}
}
k = 0;
for (i = 0; i < GRID_SIZE_X; i++)
for (j = 0; j < GRID_SIZE_Y; j++)
{
//this code implements grid on texture2D, gets vertex & side vertex in array
mass[k].nail = (i == 0 || j == 0 || i == GRID_SIZE_X - 1
|| j == GRID_SIZE_Y - 1);//value is 0/1
mass[k].x[0] = i/(GRID_SIZE_X - 1.0)*width;
// NSLog(@"mass[%d].x[0]:: %f",k,mass[k].x[0]);
mass[k].x[1] = j/(GRID_SIZE_Y - 1.0)*height;
// NSLog(@"mass[%d].x[1]:: %f",k,mass[k].x[1]);
mass[k].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;
// NSLog(@"mass[%d].x[2]:: %f",k,mass[k].x[2]);
mass[k].v[0] = 0.0;
mass[k].v[1] = 0.0;
mass[k].v[2] = 0.0;
mass[k].t[0] = i/(GRID_SIZE_X - 1.0);
mass[k].t[1] = j/(GRID_SIZE_Y - 1.0);
k++;
}
}
- (void)draw {
glDisableClientState(GL_COLOR_ARRAY);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(224,224,244,200);
[self body_redraw];
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
glEnableClientState(GL_COLOR_ARRAY);
}
我期待任何人都應該看看這個問題 – 2013-03-28 12:14:42
is'nt opengl總是加載紋理顛倒......? – 2013-03-28 16:29:44
我該如何顛倒 – 2013-04-01 14:12:16