Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
sreejond
Posts: 49
Registered: ‎03-27-2013
My Device: z10
My Carrier: Banglalink
Accepted Solution

Drawing circle into a line not working in OpenGL ES1.1

In my project I want to draw a line having cirle one of it's corner side. But I am not getting my desired output. Below is my sample code-

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	enable_2d();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	float triangle_vertex[]=
	{
		240.0f,260.0f,		//vertex 1
		260.0f,240.0f,		//vertex 2
		490.0f,510.0f,
		510.0f,490.0f		//vertex 3
	};
	GLubyte triangle_color[]=
	{
		255,0,0,255,
		255,0,0,255,
		255,0,0,255,
		255,0,0,255,
	};

	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	glLineWidth(20.0f);
	glColorPointer(4, GL_UNSIGNED_BYTE, 0, triangle_color);
	glEnableClientState(GL_COLOR_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, triangle_vertex);
	glEnableClientState(GL_VERTEX_ARRAY);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	int i;
	int triangleAmount = 20;
	GLfloat x = 500.0f;
	GLfloat y = 500.0f;
	GLfloat radius = 10.0f;
	GLfloat twicePi = 2.0f * 3.14159265358979323846f;

	GLfloat circle_vertices[2*(triangleAmount+2)+1];
	GLubyte circle_color[4*(triangleAmount+2)+1];
	circle_vertices[0] = x;
	circle_vertices[1] = y;
	circle_color[0] = 255;
	circle_color[1] = 0;
	circle_color[2] = 0;
	circle_color[3] = 255;

	for (i = 0; i <= triangleAmount; i ++) {
	    // x value
	    circle_vertices[(i*2)+2]   = x + (radius * cos(i *  twicePi / triangleAmount));
	    // y value
	    circle_vertices[(i*2+1)+2] = y + (radius * sin(i * twicePi / triangleAmount));


	    fprintf(stdout,"Circle vertex X = %f, Y = %f\n", circle_vertices[(i*2)+2], circle_vertices[(i*2+1)+2]);

	    circle_color[(i*4)+4] = 255;
		circle_color[(i*4+1)+4] = 0;
		circle_color[(i*4+2)+4] = 0;
		circle_color[(i*4+3)+4] = 255;
	}
	fprintf(stdout,"*************************************\n");
	glVertexPointer(2, GL_FLOAT, 0, circle_vertices);
	glEnableClientState(GL_VERTEX_ARRAY);
	glColorPointer(4, GL_UNSIGNED_BYTE, 0, circle_color);
	glEnableClientState(GL_COLOR_ARRAY);
	glDrawArrays(GL_TRIANGLE_FAN, 0, triangleAmount+2);

	glDisable(GL_BLEND);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

    //Use utility code to update the screen
    bbutil_swap();

 This produce the following output-

MyDrawPath.png

 

As you can see circle into my line is not drawn perfectly. But the fact is I generate the coordinate I used to draw the circle is as follow-

Circle vertex X = 510.000000, Y = 500.000000
Circle vertex X = 509.510559, Y = 503.090179
Circle vertex X = 508.090179, Y = 505.877838
Circle vertex X = 505.877838, Y = 508.090179
Circle vertex X = 503.090179, Y = 509.510559
Circle vertex X = 500.000000, Y = 510.000000
Circle vertex X = 496.909821, Y = 509.510559
Circle vertex X = 494.122162, Y = 508.090179
Circle vertex X = 491.909821, Y = 505.877838
Circle vertex X = 490.489441, Y = 503.090179
Circle vertex X = 490.000000, Y = 500.000000
Circle vertex X = 490.489441, Y = 496.909821
Circle vertex X = 491.909821, Y = 494.122162
Circle vertex X = 494.122162, Y = 491.909821
Circle vertex X = 496.909821, Y = 490.489441
Circle vertex X = 500.000000, Y = 490.000000
Circle vertex X = 503.090179, Y = 490.489441
Circle vertex X = 505.877869, Y = 491.909821
Circle vertex X = 508.090179, Y = 494.122162
Circle vertex X = 509.510559, Y = 496.909821
Circle vertex X = 510.000000, Y = 500.000000

 And the coordinate I used to draw rectangle is as follow-

float triangle_vertex[]=
	{
		240.0f,260.0f,		//vertex 1
		260.0f,240.0f,		//vertex 2
		490.0f,510.0f,
		510.0f,490.0f		//vertex 3
	};

 Now as you can see by using radious=10 my generated coordinates of the circle is comply with the reactangle.

But I can't understand why my output is wrong. According my given coordinates the circle should well matched with the rectangle. 

 

Can anyone help me regarding this issue what I actually did wrong here? I already spent a lot of time with it. But can't able to fix it. Seem to be a very minor issue but I can't help myself.

 

Thanks in advance.

Please use plain text.
Developer
sreejond
Posts: 49
Registered: ‎03-27-2013
My Device: z10
My Carrier: Banglalink

Re: Drawing circle into a line not working in OpenGL ES1.1

My calculation was wrong. Now I fix it. Thanks.

Please use plain text.