CCRenderTexture がフル ウィンドウ サイズでない場合、glDrawArrays の出力は小さくなり、奇妙な角度になります。私のテスト コードでは、対角線は角から角まで 45 度の角度で走る必要があります。この滑らかな線を正しく描くにはどうすればよいですか? 私はcocos2dが初めてで、どんな助けも大歓迎です。
//compute vertex points for smooth line triangle strip
CGPoint start = CGPointMake(0., 0.);
CGPoint end = CGPointMake(200., 200.);
float lineWidth = 10.0;
float deltaX = end.x - start.x;
float deltaY = end.y - start.y;
float length = sqrtf(deltaX*deltaX+deltaY*deltaY);
if (length < 0.25) return; //line too small to show on display
float offsetX = -lineWidth*deltaY/length;
float offsetY = lineWidth*deltaX/length;
GLfloat lineVertices[12]; //6 vertices x,y values
lineVertices[0] = start.x + offsetX;
lineVertices[1] = start.y + offsetY;
lineVertices[2] = end.x + offsetX;
lineVertices[3] = end.y + offsetY;
lineVertices[4] = start.x;
lineVertices[5] = start.y;
lineVertices[6] = end.x;
lineVertices[7] = end.y;
lineVertices[8] = start.x - offsetX;
lineVertices[9] = start.y - offsetY;
lineVertices[10] = end.x - offsetX;
lineVertices[11] = end.y - offsetY;
ccColor4F colorVertices[6];
ccColor4F color1 = {1., 0., 0., 0.};
ccColor4F color2 = {1., 0., 0., 1.};
colorVertices[0] = color1;
colorVertices[1] = color1;
colorVertices[2] = color2;
colorVertices[3] = color2;
colorVertices[4] = color1;
colorVertices[5] = color1;
CCRenderTexture *rtx = [CCRenderTexture renderTextureWithWidth:200 height:200];
[rtx beginWithClear:1. g:1. b:1. a:1.];
[shaderProgram_ use];
ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color);
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, lineVertices);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colorVertices);
glViewport(0,0, screenWidth, screenHeight); //dimensions of main screen
glDrawArrays(GL_TRIANGLE_STRIP, 0, 6);
[rtx end];
[rtx saveToFile:@"lineDrawTest" format:kCCImageFormatPNG];