Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

So what's going on with GL_POLYGON in the translate tool's arrow base? #129

Open
m-7761 opened this issue Jun 30, 2021 · 5 comments
Open
Labels

Comments

@m-7761
Copy link

m-7761 commented Jun 30, 2021

glBegin( GL_POLYGON );
glVertex2f( 0.0, 0.0 ); glVertex2f( -x1a, 0.0 );
glVertex2f( -x1a, 0.0 ); glVertex2f( -x1b, y1 );
glVertex2f( x1b, y1); glVertex2f( x1a, 0.0 );
glVertex2f( x1a, 0.0 ); glVertex2f( 0.0, 0.0 );
glEnd();
glBegin( GL_TRIANGLES );
glVertex2f( -x2, y1 ); glVertex2f( 0.0, y2 ); glVertex2f( x2, y1 );
glEnd();

FWIW here's some code that can replace it. I was adding an OpenGL ES mode (ANGLE) when I noticed this ... I don't know how I ever missed it before. I know I spent a lot of time with this subroutine. I just can't think of a rationale for using GL_POLYGON here so I'm curious. Notice also two vertics are duplicated.

gl::glBegin(GL_QUADS);
gl::glVertex2f(-x1a,0);
gl::glVertex2f(-x1b,y1);
gl::glVertex2f(x1b,y1);
gl::glVertex2f(x1a,0);
gl::glEnd();
@nigels-com
Copy link
Collaborator

It's an OpenGL codebase. It predates ES by at least a decade.

@m-7761
Copy link
Author

m-7761 commented Jul 1, 2021

I can never tell if you're being deliberately disturbing (@nigels-com) but FWIW what I think is the best explanation here is once upon a time this 8 sided polygon formed an arrow head with a 90 degree spike sticking out of the base, that would be flattened for the double-sided arrow. Much like the rest of the GLUI code it lacks a lot in the way of commonsense... I think someone came along and turned this 8 sided polygon into a square and added a second triangle to form an arrow... instead of doing the reasonable thing of drawing a quad and a triangle they felt for some reason it was important to preserve the original code that used the polygon... this OCD like tendency could explain why GLUI's code is so maddening (and completely untenable in terms of performance) throughout. (Edited: As for myself I just can't believe I never noticed that this polygon made no sense back when I was working on improving/overhauling GLUI. It seems I never stopped to look at it critically.)

@nigels-com
Copy link
Collaborator

It's old code.
You want to hunt down the author and shame them, or something?
That's not a stance I subscribe to.

Good for you for taking it forward into the modern age.

@m-7761
Copy link
Author

m-7761 commented Jul 1, 2021

[I initially thought it would have been some kind of arcane OpenGL trickery. It only later occurred to me it could have originally drawn the whole arrow instead of just the part beneath the triangle tip.]

I realized after figuring out what the old polygon code was that it actually was possible to draw the arrow as a polygon (fan) if the tip of the arrow is the pivot. So this would be a better replacement. I've never understood what the GLUI project was for since it would not make simple changes like this one, as if it had some existential purpose besides functional code.

	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(0,y2);
	glVertex2f(-x2,y1);
	glVertex2f(-x1b,y1);
	glVertex2f(-x1a,0); //y0
	glVertex2f(x1a,0); //y0
	glVertex2f(x1b,y1);
	glVertex2f(x2,y1);
	glEnd();

@nigels-com
Copy link
Collaborator

nigels-com commented Jul 1, 2021

All pull requests are given due consideration, as always.

Primarily GLUI is maintained for purpose of existing GLUI applications.
In that context stability is prized, breaking changes would need significant justification.
Along with that, there is some burden to prove that changes are not without their own side effects. (testing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants