OpenGL, C++ Cornered Box -


i have been working on gui menu game (school project) have engine template ready need make gui menu. me , friend teacher have managed make non filled box here function:

void boxtest(float x, float y, float width, float height, float width, color color) { gllinewidth(3); glbegin(gl_line_loop); glcolor4f(0, 0, 0, 1); glvertex2f(x, y); glvertex2f(x, y + height); glvertex2f(x + width, y + height); glvertex2f(x + width, y); glend(); gllinewidth(1); glbegin(gl_line_loop); glcolor4f(color.r, color.g, color.b, color.a); glvertex2f(x, y); glvertex2f(x, y + height); glvertex2f(x + width, y + height); glvertex2f(x + width, y); glend(); } 

this how looks now: http://gyazo.com/c9859e9a8e044e1981b3fe678f4fc9ab

the problem want this: http://gyazo.com/0499dd8324d24d63a54225bd3f28463d

becuse looks better, me , friend has been sitting here couple of days no clue on how achive this.

with opengl line primitives you'll have break down multiple lines. gl_line_loop makes a series of lines, connected each other , closed @ end. not want. instead should use simple gl_lines. every 2 glvertex calls (btw: shouldn't use those, because glvertex terribly outdated; it's been out of fashion 20 years) make 1 line.

let's @ ascii art:

0 --- 1    4 --- 3 |                | 2                5  8                b |                | 6 --- 7    --- 9 

you'd draw line segments

  • 0 – 1
  • 0 – 2
  • 3 – 4
  • 3 – 5
  • 6 – 7
  • 6 – 8
  • 9 – a
  • 9 – b

replace symbols 0…b coordinates of each point , can make this

glbegin(gl_lines);  glvertex( coords[0] ); glvertex( coords[1] ); glvertex( coords[0] ); glvertex( coords[2] );  glvertex( coords[3] ); glvertex( coords[4] ); glvertex( coords[3] ); glvertex( coords[5] );  glvertex( coords[6] ); glvertex( coords[7] ); glvertex( coords[6] ); glvertex( coords[8] );  glvertex( coords[9] ); glvertex( coords[0xa] ); glvertex( coords[9] ); glvertex( coords[0xb] );  glend(); 

as final touch can load coords array opengl vertex array , use gldrawarrays or gldrawelements instead.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -