Jump to content
  • Advertisement
Sign in to follow this  
speciesUnknown

wonky cursor border but not body, same data.

This topic is 3965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been playing around with GUI systems and made this custom cursor. The shape is drawn first, followed by the a white border. Strangly, the shape is the correct shape, but the border is wonky. Here is an image of the cursor: As you can see, they both use the same data. Scaling the cursor makes no difference, as the superimposed sub images demonstrate. and here is the code to draw it:

void GUI_cursor::draw(float fps, float X, float Y)
{
	float points[45] = {
		0,0,
		-0.736,0.733, 
		-0.736,0.272, 
		-1.094,0.615, 
		 -1.212,0.463,
		 -0.832,0.2431,
		 -1.075,0
	};


	unsigned int index;
	const float scale = 80;
	glColor4f(0,0,0,1);
	index = 0;
	glPushMatrix();
		glTranslatef(xpos+X, ypos+Y,0);
		glBegin(GL_POLYGON);
		for(int p = 0; p < 7; p++){
			glVertex2f(points[index++]*scale,points[index++]*scale);
		}
		glEnd();
		
		index = 0;
		glColor4f(1,1,1,1);
		glBegin(GL_LINE_LOOP);
		for(int p = 0; p < 7; p++){
			glVertex2f(points[index++]*scale,points[index++]*scale);
		}
		glEnd();
	glPopMatrix();
};

I don't want to replace the cursor with an image since this GUI library is not supposed to be all-singing all-dancing, I'm just doing it for learning purposes. But I'd like to know the problem behind the strange border.

Share this post


Link to post
Share on other sites
Advertisement
glBegin(GL_POLYGON)...glEnd() can only be used to draw convex polygons, whereas your cursor is concave. So, in fact, the border is the correct shape (according to your data points) and the body is being drawn incorrectly.

I suggest splitting the body into a set of convex polygons.

Share this post


Link to post
Share on other sites
Quote:
Original post by bakery2k1
glBegin(GL_POLYGON)...glEnd() can only be used to draw convex polygons, whereas your cursor is concave. So, in fact, the border is the correct shape (according to your data points) and the body is being drawn incorrectly.

I suggest splitting the body into a set of convex polygons.


Ok, so the data was wrong, and the body only appeared correct due to being drawn in the wrong mode. I've tweaked the corner with the problem and now the cursor looks as I intended. I think I'll leave in the convex polygon problem, since its not causing any visual problem.

Thanks, bakery2kl.

Share this post


Link to post
Share on other sites
Quote:
Original post by speciesUnknown
I think I'll leave in the convex polygon problem, since its not causing any visual problem.

Not on your card, on your OS, with your currently installed driver. On any other combination, you can't rely on it looking at all like this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!