line - glDrawArrays distorts output to CCRenderTexture -


if ccrendertexture not full window size, gldrawarrays output smaller , @ strange angle. in test code, diagonal line should run corner corner @ 45 degree angle. how can draw smooth line correctly? i'm new cocos2d , appreciated.

//compute vertex points 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 small 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]; 

i added glviewport call set view original full screen size. gldrawarrays draws smooth line right size , angle.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -