i am using this file to display png file but to display pvrtexture i am having problem i have converted the png file into pvrtexture.i have looked at pvrtextureloader ex also but no result.
plz help thanks in advance
graphics=[SCGraphics getInstance]; splashscreenImage=[SCGraphics loadImageFilename:@"blue.png"]; [graphics drawImage:splashscreenImage X:0 Y:0 Anchor:(TOP | LEFT)];
SCGraphics file***************
include
include
include
import "SCGraphics.h"
import "Texture2D.h"
import "CommonDefinitions.h"
SCGraphics *mainGraphics;
@implementation SCGraphics
+(SCGraphics *) getInstance{ if(mainGraphics == NULL){ mainGraphics = [SCGraphics alloc] ; [mainGraphics initGraphics]; } return mainGraphics; }
/////////////////////////////////////////////////////////////////////////////////////////////
+(Image *) loadImageFilename: (NSString *) fileName{
GLuint textureID;
BOOL sizeToFit = NO;
int i = 0;
//NSLog(@"%@",[UIImage imageNamed:fileName].CGImage);
CGImageRef textureImage = [UIImage imageNamed:fileName].CGImage;
//CGImageRef textureImage = [UIImage imageWithContentsOfFile:fileName].CGImage;
if (textureImage == nil) {
NSLog(@"Failed to load texture image");
return NULL;
}
NSInteger texWidth = CGImageGetWidth(textureImage);
NSInteger texHeight = CGImageGetHeight(textureImage);
NSInteger texWidthAdj = texWidth;
NSInteger texHeightAdj = texHeight;
if((texWidthAdj != 1) && (texWidthAdj & (texWidthAdj - 1))) {
i = 1;
while((sizeToFit ? 2 * i : i) < texWidthAdj)
i *= 2;
texWidthAdj = i;
}
if((texHeightAdj != 1) && (texHeightAdj & (texHeightAdj - 1))) {
i = 1;
while((sizeToFit ? 2 * i : i) < texHeightAdj)
i *= 2;
texHeightAdj = i;
}
GLubyte *textureData = (GLubyte *)malloc(texWidthAdj * texHeightAdj * 4);
CGContextRef textureContext = CGBitmapContextCreate(textureData,
texWidthAdj, texHeightAdj,
8, texWidthAdj * 4,
CGImageGetColorSpace(textureImage),
kCGImageAlphaPremultipliedLast);
// Rotate the image
CGContextTranslateCTM(textureContext, 0,texHeightAdj - (texHeightAdj - texHeight));
CGContextScaleCTM(textureContext, 1.0, -1.0);
CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)texWidth, (float)texHeight), textureImage);
CGContextRelease(textureContext);
// Use OpenGL ES to generate a name for the texture.
glGenTextures( 1, &textureID );
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidthAdj, texHeightAdj, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
free(textureData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLfloat textureCoordinates [ 8 ];
GLfloat adjustmentX,adjustmentY;
// if(texHeight > texWidth){
// adjustmentY = texHeight/(GLfloat)texWidth;
// adjustmentX = 1.0;
//
// }else if(texHeight < texWidth){
// adjustmentX = texWidth/(GLfloat)texHeight;
// adjustmentY = 1.0;
//
// }else if(texHeight == texWidth){
adjustmentX = 1.0;
adjustmentY = 1.0;
// }
textureCoordinates[ 0 ] = 0.0f;
textureCoordinates[ 1 ] = 1.0f * adjustmentY;
textureCoordinates[ 2 ] = 0.0f;
textureCoordinates[ 3 ] = 0.0f;
textureCoordinates[ 4 ] = 1.0f * adjustmentX;
textureCoordinates[ 5 ] = 0.0f;
textureCoordinates[ 6 ] = 1.0f * adjustmentX;
textureCoordinates[ 7 ] = 1.0f * adjustmentY;
// return Image( textureID, texWidth, texHeight, textureCoordinates );
Image* toret = [[Image alloc] ImagetexId:textureID imgWidth:texWidthAdj imgHeight:texHeightAdj texCoordinates:textureCoordinates];
return toret;
}
/////////////////////////////////////////////////////////////////////////////////////////////
-(void) initGraphics{ iClipX = 0; iClipY = 0; iClipWidth = DEVICE_SCREENWIDTH; iClipHeight = DEVICE_SCREENHEIGHT;
for(int i=0, j= 0;i <= ARRAY_SIZE(circlePoints)/2;i++, j+=2)
{
int segmentDegree = i*(360/(ARRAY_SIZE(circlePoints)/2));
if(j == ARRAY_SIZE(circlePoints))
{
circlePoints[j-2] = cos(DEGTORAD(segmentDegree));
circlePoints[j-1] = sin(DEGTORAD(segmentDegree));
}
else
{
circlePoints[j] = cos(DEGTORAD(segmentDegree));
circlePoints[j+1] = sin(DEGTORAD(segmentDegree));
}
}
printf("in initgraphics");
}
-(void) drawRectx: (GLfloat) x y: (GLfloat) y w: (GLfloat) w h: (GLfloat) h {
glPushMatrix();
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)(y+h);
rVertices4[ 4 ] = (GLfloat)(x+w);
rVertices4[ 5 ] = (GLfloat)(y+h);
rVertices4[ 6 ] = (GLfloat)(x+w);
rVertices4[ 7 ] = (GLfloat)y;
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glDrawArrays( GL_LINE_LOOP, 0, 4 );
//glDisableClientState( GL_VERTEX_ARRAY );
//
glPopMatrix();
}
-(void) fillRectx: (GLfloat) x y: (GLfloat) y w: (GLfloat) w h: (GLfloat) h { // glPushMatrix();
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)(x+w);
rVertices4[ 3 ] = (GLfloat)y;
rVertices4[ 4 ] = (GLfloat)x;
rVertices4[ 5 ] = (GLfloat)(y+h);
rVertices4[ 6 ] = (GLfloat)(x+w);
rVertices4[ 7 ] = (GLfloat)(y+h);
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
//glDisableClientState( GL_VERTEX_ARRAY );
//
glPopMatrix();
}
-(void) drawEllipsex: (GLfloat) x y: (GLfloat) y w: (GLfloat) w h: (GLfloat) h{
glPushMatrix();
glTranslatef(x+w/2, y+h/2, 0.0f);
glScalef(w/2,h/2, 1.0f);
glVertexPointer(2, GL_FLOAT, 0, circlePoints);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, ARRAY_SIZE(circlePoints)/2);
glPopMatrix();
}
-(void) fillArcX: (GLfloat) x y: (GLfloat) y w: (GLfloat) w h: (GLfloat) h Angle:(GLfloat) angle Sweep:(GLfloat) sweep{ GLfloat radius, sx, sy, xx, yy, p;
bool quadrant[] =
{
false,
false,
false,
false
};
int xcenter = x + (abs(w)>>1);
int ycenter = y + (abs(h)>>1);
int width = abs(w)>>1;
int height = abs(h)>>1;
GLfloat start = angle;
GLfloat end = sweep;
//start = (start / 90) * 90;
//end = (end / 90) * 90;
if (start < 0 || end < 0)
{
start = (abs((int)start % 360) + 360) % 360;
end = (abs((int)end % 360) + 360) % 360;
}
if (end < start)
{
GLfloat tmp = start;
start = end;
end = tmp;
}
for (int degree = start; degree < end; degree += 90)
{
quadrant[degree / 90] = true;
}
if (width < height)
{
sx = width / height;
sy = 1.0f;
radius = height;
}
else
{
sx = 1.0f;
sy = height / width;
radius = width;
}
xx = 0.0f;
yy = radius;
p = (1.25f)-radius;
//
glPushMatrix();
glTranslatef(xcenter, ycenter, 0.0f);
glScalef(sx, sy, 1.0);
rVertices2[ 0 ] = -radius;
rVertices2[ 1 ] = 0.0f;
rVertices2[ 2 ] = radius;
rVertices2[ 3 ] = 0.0f;
if (!quadrant[0] && !quadrant[1]) rVertices2[2] = 0.0f;
if (!quadrant[2] && !quadrant[3]) rVertices2[0] = 0.0f;
glVertexPointer(2, GL_FLOAT, 0, rVertices2 );
glDrawArrays(GL_LINES, 0, 2);
do
{
if (p < 0)
{
xx+=0.5f;
p = p + (xx + xx) + 1.0f;
GLfloat lineVertices[] =
{
-yy, xx,
yy, xx,
-yy, -xx,
yy, -xx,
};
if (!quadrant[0]) lineVertices[2] = 0.0f;
if (!quadrant[1]) lineVertices[6] = 0.0f;
if (!quadrant[2]) lineVertices[4] = 0.0f;
if (!quadrant[3]) lineVertices[0] = 0.0f;
glVertexPointer( 2, GL_FLOAT, 0, lineVertices );
glDrawArrays( GL_LINES, 0, 4 );
}
else
{
xx += 0.5f;
yy -= 0.5f;
p = p + (xx + xx) + 1.0f - (yy + yy);
GLfloat lineVertices[] =
{
-xx, yy,
xx, yy,
-yy, xx,
yy, xx,
-yy, -xx,
yy, -xx,
-xx, -yy,
xx, -yy,
};
if (!quadrant[0])
{
lineVertices[2] = 0.0f;
lineVertices[6] = 0.0f;
}
if (!quadrant[1])
{
lineVertices[10] = 0.0f;
lineVertices[14] = 0.0f;
}
if (!quadrant[2])
{
lineVertices[8] = 0.0f;
lineVertices[12] = 0.0f;
}
if (!quadrant[3])
{
lineVertices[0] = 0.0f;
lineVertices[4] = 0.0f;
}
glVertexPointer(2, GL_FLOAT, 0, lineVertices);
glDrawArrays(GL_LINES , 0, 8);
}
}
while(xx < yy);
//
glPopMatrix();
}
-(void) drawLineXA: (GLfloat) xa YA:(GLfloat) ya XB:(GLfloat) xb YB:(GLfloat) yb{
//
glPushMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
rVertices2[ 0 ] = (GLfloat)xa;
rVertices2[ 1 ] = (GLfloat)ya;
rVertices2[ 2 ] = (GLfloat)xb;
rVertices2[ 3 ] = (GLfloat)yb;
// glLineWidth( 2.0f );
glVertexPointer(2, GL_FLOAT, 0, rVertices2 );
glDrawArrays(GL_LINES, 0, 2);
//glDisableClientState(GL_VERTEX_ARRAY);
//
glPopMatrix();
}
//-(void) drawPoint: (GLfloat) xPos YA:(GLfloat) yPos{
// glPushMatrix();
// glEnableClientState(GL_VERTEX_ARRAY);
// rVertices2[ 0 ] = (GLfloat)xPos;
// rVertices2[ 1 ] = (GLfloat)yPos;
// rVertices2[ 2 ] = (GLfloat)xPos+1;
// rVertices2[ 3 ] = (GLfloat)yPos+1;
//
// glVertexPointer(2, GL_FLOAT, 0, rVertices2);
// glDrawArrays(GL_POINTS, 0, 2);
//
// glPopMatrix();
//}
-(void) fillTriangleX0:(GLfloat) x0 Y0:(GLfloat) y0 X1:(GLfloat) x1 Y1:(GLfloat) y1 X2:(GLfloat) x2 Y2:(GLfloat) y2
{
//
glPushMatrix();
rVertices3[ 0 ] = (GLfloat)x0;
rVertices3[ 1 ] = (GLfloat)y0;
rVertices3[ 2 ] = (GLfloat)x1;
rVertices3[ 3 ] = (GLfloat)y1;
rVertices3[ 4 ] = (GLfloat)x2;
rVertices3[ 5 ] = (GLfloat)y2;
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, rVertices3 );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
//glDisableClientState(GL_VERTEX_ARRAY);
//
glPopMatrix();
}
-(void) setColorRed:(GLfloat) red Green:(GLfloat) green Blue:(GLfloat) blue{ glColor4f( TOFLOAT(red), TOFLOAT(green), TOFLOAT(blue), 1.0f ); }
-(void) drawPointXpos: (GLfloat) xpos Ypos:(GLfloat) ypos{
glPushMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
rVertices2[ 0 ] = (GLfloat)xpos;
rVertices2[ 1 ] = (GLfloat)ypos;
rVertices2[ 2 ] = (GLfloat)xpos+1.0f;
rVertices2[ 3 ] = (GLfloat)ypos+1.0f;
// glLineWidth( 2.0f );
glVertexPointer(2, GL_FLOAT, 0, rVertices2 );
glDrawArrays(GL_LINES, 0, 2);
//glDisableClientState(GL_VERTEX_ARRAY);
//
glPopMatrix();
}
-(void)drawImage:(Image*)img X:(GLfloat) x Y:(GLfloat) y totNoofrows:(GLfloat)row totalNoofcoloum:(GLfloat)col rowposofimage:(GLfloat)prow colposofimage:(GLfloat)pcol {
GLfloat x0,y0,x1,y1,x2,y2,x3,y3;
x0=0+((1/(float)col)*pcol);
y0=1-((1/(float)row)*prow);
x1=0+((1/(float)col)*pcol);
y1=1-((1/(float)row)*(prow+1));
x2=0+((1/(float)col)*(pcol+1));
y2=1-((1/(float)row)*(prow+1));
x3=0+((1/(float)col)*(pcol+1));
y3=1-((1/(float)row)*prow);
const GLfloat combinedTextureCoordinate[]={
x0,y0,
x1,y1,
x2,y2,
x3,y3
};
GLfloat x11 = x + (img.width/col);
GLfloat y11 = y + (img.height/row);
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y11;
rVertices4[ 4 ] = (GLfloat)x11;
rVertices4[ 5 ] = (GLfloat)y11;
rVertices4[ 6 ] = (GLfloat)x11;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, img.textureID);
glVertexPointer(2, GL_FLOAT, 0, rVertices4);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, &combinedTextureCoordinate[0]);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
glDisable( GL_TEXTURE_2D );
glPopMatrix();
}
-(void) drawScaleImage: (Image*) img X:(GLfloat) x Y:(GLfloat) y Scale:(GLfloat) scale{
if( img == NULL )
{
return;
}
GLfloat transX = x;
GLfloat transY = y;
x = 0;
y = 0;
// GLfloat x1 = img.width + x; // GLfloat y1 = img.height + y;
GLfloat x1 = img.width + transX;
GLfloat y1 = img.height + transY;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX, transY, 1.0);
glScalef(scale, scale, 1.0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
}
-(void) drawImageAtPoint: (Image*) img X:(GLfloat) x Y:(GLfloat) y{
if( img == NULL )
{
return;
}
GLfloat transX = x;
GLfloat transY = y;
x = 0;
y = 0;
GLfloat x1 = img.width + transX;
GLfloat y1 = img.height + transY;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX, transY, 1.0);
//glScalef(scale, scale, 1.0);
//glScalef(0, 0, 0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
}
-(void) drawScaleImageByHeight: (Image*) img X:(GLfloat) x Y:(GLfloat) y Scale:(GLfloat) scale Height:(GLfloat) height{ if( img == NULL ) { return; } GLfloat transX = x; GLfloat transY = y; x = 0; y = 0; GLfloat x1 = img.width; GLfloat y1 = height;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX, transY, 1.0);
// glScalef(scale, scale, 1.0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
} -(void) drawScaleImageByWidth: (Image*) img X:(GLfloat) x Y:(GLfloat) y Scale:(GLfloat) scale Width:(GLfloat) width{
if( img == NULL )
{
return;
}
GLfloat transX = x;
GLfloat transY = y;
x = 0;
y = 0;
GLfloat x1 = width;
GLfloat y1 = img.height;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX, transY, 1.0);
// glScalef(scale, scale, 1.0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
} -(void) drawTVRightOpen: (Image*) img X:(GLfloat) x Y:(GLfloat) y Scale:(GLfloat) scale Width:(GLfloat) height{
if( img == NULL )
{
return;
}
GLfloat transX = x;
GLfloat transY = y;
x = 0;
y = 0;
GLfloat x1 = img.width;
GLfloat y1 = height;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX, transY, 1.0);
// glScalef(scale, scale, 1.0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
}
-(void) drawScaleImageByWidthAndHeight: (Image*) img X:(GLfloat) x Y:(GLfloat) y Scale:(GLfloat) scale Width:(GLfloat) width Height:(GLfloat) height{ if( img == NULL ) { return; } GLfloat transX = x; GLfloat transY = y; x = 0; y = 0; GLfloat x1 = width; GLfloat y1 = height;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX, transY, 1.0);
// glScalef(scale, scale, 1.0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
} -(void) drawRotateImage: (Image*) img X:(GLfloat) x Y:(GLfloat) y Rotate:(GLfloat) rot{
if( img == NULL )
{
return;
}
GLfloat transX = x;
GLfloat transY = y;
// x = -(img.width>>1); // y = -(img.height>>1);
x = -27.5;
y = -27.5;
GLfloat x1 = img.width + x;
GLfloat y1 = img.height + y;
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTranslatef(transX , transY , 1.0);
// glRotatef(DEGTORAD(rot), 0.0, 0.0, 1.0); glRotatef(rot, 0.0, 0.0, 1.0); glDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); // glDrawTexiOES( x, y, 0, (img.width), (img.height) ); glDisable( GL_TEXTURE_2D ); glPopMatrix();
}
(void) drawImage: (Image*) img X:(GLfloat) x Y:(GLfloat) y Anchor:(GLfloat) anchor { if( img == NULL ) { return; }
img.initX=x;// img.initY=y;// GLfloat x1; GLfloat y1; if(anchor == (TOP | LEFT)){ x1 = img.width + x; y1 = img.height + y; }else if(anchor == (VCENTER | HCENTER)){ x -= (img.width/2); y -= (img.height/2); x1 = img.width + x; y1 = img.height + y; }else if(anchor == (BOTTOM | RIGHT)){ x1 = img.width + x; y1 = img.height + y; }else if(anchor == (BOTTOM | LEFT)){ x1 = img.width + x; y1 = img.height + y; } else{ x1 = img.width + x; y1 = img.height + y; }
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
}
-(void) drawImageTransform: (Image*) img X:(GLfloat) x Y:(GLfloat) y Tramsform:(int) transform Scale:(float)scale { GLfloat x1 = img.width + x; GLfloat y1 = img.height + y;
switch( transform )
{
case TRANS_MIRROR_ROT180:
{
//pt4 c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y1;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y1;
break;
}
case TRANS_MIRROR:
{
//pt2 c
rVertices4[ 0 ] = (GLfloat)x1;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x1;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x;
rVertices4[ 7 ] = (GLfloat)y;
break;
}
case TRANS_ROT180:
{
//pt3 anti-c
rVertices4[ 0 ] = (GLfloat)x1;
rVertices4[ 1 ] = (GLfloat)y1;
rVertices4[ 2 ] = (GLfloat)x1;
rVertices4[ 3 ] = (GLfloat)y;
rVertices4[ 4 ] = (GLfloat)x;
rVertices4[ 5 ] = (GLfloat)y;
rVertices4[ 6 ] = (GLfloat)x;
rVertices4[ 7 ] = (GLfloat)y1;
break;
}
case TRANS_MIRROR_ROT270:
{
//pt1 c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x1;
rVertices4[ 3 ] = (GLfloat)y;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x;
rVertices4[ 7 ] = (GLfloat)y1;
break;
}
case TRANS_ROT90:
{
//pt2 anti-c
rVertices4[ 0 ] = (GLfloat)x1;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y;
rVertices4[ 4 ] = (GLfloat)x;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y1;
break;
}
case TRANS_ROT270:
{
//pt4 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y1;
rVertices4[ 2 ] = (GLfloat)x1;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y;
rVertices4[ 6 ] = (GLfloat)x;
rVertices4[ 7 ] = (GLfloat)y;
break;
}
case TRANS_MIRROR_ROT90:
{
//pt3 c
rVertices4[ 0 ] = (GLfloat)x1;
rVertices4[ 1 ] = (GLfloat)y1;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x;
rVertices4[ 5 ] = (GLfloat)y;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
break;
}
//TRANS_NONE
default:
{
//pt1 anti-c
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)y1;
rVertices4[ 4 ] = (GLfloat)x1;
rVertices4[ 5 ] = (GLfloat)y1;
rVertices4[ 6 ] = (GLfloat)x1;
rVertices4[ 7 ] = (GLfloat)y;
break;
}
}
ifdef TST_CLIP
if( (x1 <= 0) && (y1 <= 0) )
return;
endif
//
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates] );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glScalef(scale, scale, 1.0);
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
}
-(void) drawImage: (Image*) img X:(GLfloat) x Y:(GLfloat) y ClipX:(GLfloat) clipX ClipY:(GLfloat) clipY ClipWidth:(GLfloat) clipWidth ClipHeight:(GLfloat) clipHeight{
if( img == NULL )
{
return;
}
float c_x;
float c_y;
float c_w;
float c_h;
c_x = x+clipX;
c_y = y+clipY;
c_w = c_x+clipWidth;
c_h = c_y+clipHeight;
rVertices4[ 0 ] = (GLfloat)x;
rVertices4[ 1 ] = (GLfloat)y;
rVertices4[ 2 ] = (GLfloat)x;
rVertices4[ 3 ] = (GLfloat)c_y;
rVertices4[ 4 ] = (GLfloat)c_x;
rVertices4[ 5 ] = (GLfloat)c_y;
rVertices4[ 6 ] = (GLfloat)c_w;
rVertices4[ 7 ] = (GLfloat)c_h;
// -(void) drawLineXA: (GLfloat) xa YA:(GLfloat) ya XB:(GLfloat) xb YB:(GLfloat) yb{
// [self drawLineXA:x YA:y XB:c_x YB:c_y] ;
glPushMatrix();
//glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, img.textureID );
glVertexPointer( 2, GL_FLOAT, 0, rVertices4 );
glEnableClientState( GL_VERTEX_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, [img getCordinates]);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
// glDrawTexiOES( x, y, 0, (img.width), (img.height) );
glDisable( GL_TEXTURE_2D );
//
glPopMatrix();
}
UIImage pictureView; -(void) drawImageRotation:(Image) img{ if(pictureView==nil) { } }
-(void) dealloc { if(mainGraphics != NULL) mainGraphics = NULL;
[super dealloc];
}
@end