2012-01-31 3 views
2

OpenGL ESに奇妙な問題があります。私は[GLPaintアプリから参照を取得する] iphone用のペイントアプリケーションに取り組んでいます。私のコードでは、色を塗りつぶすために[CAEAGLLayer] paintViewを配置しているアウトラインイメージを含むimageViewを使用しています。私は、ユーザが触れる場所に基づいて、画面上の線でアウトラインイメージに色を塗りつぶしています。私は開始点と終了点を取得するために "touchesMoved"を使用して2つの点の間に線を描くために "renderLineFromPoint"関数を使用しています。ペイントアプリケーション用のOpenGL ESコンテンツをズームしながらIphoneピクセルの歪み

- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end{ 

//画面上のユーザーは、私がピンチジェスチャー使用してペイントビューをズームしています今

static GLfloat*  vertexBuffer = NULL; 
static NSUInteger vertexMax = 64; 

NSUInteger   vertexCount = 0, 
        count, 
        i; 

[EAGLContext setCurrentContext:context]; 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); 

// Convert locations from Points to Pixels 
//CGFloat scale = self.contentScaleFactor; 
CGFloat scale; 
if ([self respondsToSelector: @selector(contentScaleFactor)]) 
{ 

    scale=self.contentScaleFactor; 

} 
else{ 


//scale = 1.000000; 

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) { 
     // RETINA DISPLAY 

     scale = 2.000000; 
    } 
    else { 
     scale = 1.000000; 
    } 

} 




start.x *= scale; 
start.y *= scale; 
end.x *= scale; 
end.y *= scale; 

float dx = end.x - start.x; 
float dy = end.y - start.y; 
float dist = (sqrtf(dx * dx + dy * dy)/ kBrushPixelStep); 

// Allocate vertex array buffer 
if(vertexBuffer == NULL)  
vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat)); 


// Add points to the buffer so there are drawing points every X pixels 

count = MAX(ceilf(dist), 1); 

//NSLog(@"count %d",count); 

for(i = 0; i < count; ++i) { 
    if(vertexCount == vertexMax) { 
     vertexMax = 2 * vertexMax; 
     vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat)); 

    // NSLog(@"if loop"); 

    } 



    vertexBuffer[2 * vertexCount + 0] = start.x + (dx) * ((GLfloat)i/(GLfloat)count); 
    vertexBuffer[2 * vertexCount + 1] = start.y + (dy) * ((GLfloat)i/(GLfloat)count); 

    vertexCount += 1; 


} 





// Render the vertex array 
glVertexPointer(2, GL_FLOAT, 0, vertexBuffer); 





glDrawArrays(GL_POINTS, 0, vertexCount); 


    // Display the buffer 



glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); 
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; 


} 

に触れる場所に基づいて線画:上記のコード

UIPinchGestureRecognizer *twoFingerPinch = 
[[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)] autorelease]; 
[self addGestureRecognizer:twoFingerPinch]; 



- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{ 



if([recognizer state] == UIGestureRecognizerStateBegan) { 
    // Reset the last scale, necessary if there are multiple objects with different scales 
    lastScale = [recognizer scale]; 
} 

if ([recognizer state] == UIGestureRecognizerStateBegan || 
    [recognizer state] == UIGestureRecognizerStateChanged) { 

    CGFloat currentScale = [[[recognizer view].layer valueForKeyPath:@"transform.scale"] floatValue]; 

    // Constants to adjust the max/min values of zoom 
    const CGFloat kMaxScale = 2.0; 
    const CGFloat kMinScale = 1.0; 

    CGFloat newScale = 1 - (lastScale - [recognizer scale]); 
    newScale = MIN(newScale, kMaxScale/currentScale); 
    newScale = MAX(newScale, kMinScale/currentScale); 
    CGAffineTransform transform = CGAffineTransformScale([self transform], newScale, newScale); 
    self.transform = transform; 

    lastScale = [recognizer scale]; // Store the prev 

    textureScale = lastScale; 




    [self setContentScaleFactor:2.0f]; 


    CGRect frame = self.bounds; 


    NSLog(@"Scale %f Last scale %f width %f Height %f", newScale , lastScale, frame.size.width * newScale, frame.size.height * newScale); 



} 

} 

は、ズーム後に働いているが、 paintView上の線はピクセル[網膜表示ではありません]を歪ませています。

ズームスケールに基づいてOpenGLの内容を再描画する方法はありますか。

ありがとうございました。

答えて

3

全く奇妙ではありません。 OpenGLに描画すると、固定解像度で描画され、解像度はOpenGLコンテキストのサイズになります。画面の解像度であるコンテキストを作成する可能性が最も高いです。

イメージを補間せずにズームインできるようにするには、画面よりも大きなGLコンテキストを作成する必要があります。たとえば、200%に拡大するには、画面のピクセル数の2倍のコンテキストを作成する必要があります。

+0

こんにちはジェシュア、本当にありがとうございます。それは私のために働いた。 – user392406

関連する問題