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

GL_COLOR_ARRAY is not working glDrawArrays() in OpenGL ES 1.1

Hello everyone,

 

My target is to draw a polyline from a set of vertex. To do so I did some coding below. But the problem is I draw the polyline correctly but I can't assing color into it. I used an array to set my color for each vertex and then draw it using glDrawArrays(). But unfortunately I didn't get my required color(red). 

 

Can anybody please review my code what I am doing wrong here? I am using OpenGL ES 1.1. Below is my sample code-

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	enable_2d();

	glEnable(GL_TEXTURE_2D);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnable(GL_LINE_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	float line_vertex[]=
	{
		250.0f,250.0f,		//vertex 1
		500.0f,500.0f,	//vertex 2
		500.0f,200.0f		//vertex 3
	};
	float line_color[]=
	{
		1.0f,0.0f,0.0f,
		1.0f,0.0f,0.0f,
		1.0f,0.0f,0.0f
	};

//	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	glLineWidth(10.0f);
	glVertexPointer(2, GL_FLOAT, 0, line_vertex);
	glColorPointer(3, GL_FLOAT, 0, line_color);
	glDrawArrays(GL_LINE_STRIP, 0, 3);

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

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

 

Please use plain text.
Developer
useful
Posts: 26
Registered: ‎09-23-2012
My Device: Playbook, Z10LE
My Carrier: tnl

Re: GL_COLOR_ARRAY is not working glDrawArrays() in OpenGL ES 1.1

As an alternative try the functions glDrawArrays() to use GL_TRIANGLE_FAN.

Please use plain text.
New Developer
johncmurphy
Posts: 3
Registered: ‎03-30-2013
My Device: N/A
My Carrier: N/A

Re: GL_COLOR_ARRAY is not working glDrawArrays() in OpenGL ES 1.1

The problem is that you are using a float type for the line_color array.

Try an unsigned byte or short instead:

 

GLubyte line_color[] = {
            255,0,0,255,
            255,0,0,255,
            255,0,0,255,
            255,0,0,255,
}

 

And change the glColorPointer call accordingly:

glColorPointer(4, GL_UNSIGNED_BYTE, 0, line_color);
Please use plain text.