I am trying to map a texture to a circle using GL_POLYGON with this code:
GL_POLYGON
void drawCircleOutline(Circle c, int textureindex) { float angle, radian, x, y; // values needed by drawCircleOutline glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureLib[textureindex]); glBegin(GL_POLYGON); for (angle=0.0; angle<360.0; angle+=2.0) { radian = angle * (pi/180.0f); x = (float)cos(radian) * cr + c.pos.x; y = (float)sin(radian) * cr + c.pos.y; glTexCoord2f(x, y); glVertex2f(x, y); } glEnd(); glDisable(GL_TEXTURE_2D); }
It looks like at startup.
And it should look like this:
Try:
radian = angle * (pi/180.0f); xcos = (float)cos(radian); ysin = (float)sin(radian); x = xcos * cr + c.pos.x; y = ysin * cr + c.pos.y; tx = xcos * 0.5 + 0.5; ty = ysin * 0.5 + 0.5; glTexCoord2f(tx, ty); glVertex2f(x, y);
Source: https://habr.com/ru/post/905342/More articles:Setting the time zone by default does not work, although the time zone is valid - timezoneRandom walks in directed graphs / networks - cWhat is the best way to make a try block break between them? - javaPayPal integration in C # /. NET solution using WSDL (SOAP) - c #Getting tkinter StringVar () error on initialization - pythonHow to implement a simple button in PyQt - pythonSome Simple Ruby Questions - Iterators, Blocks, and Symbols - ruby โโ| fooobar.comHow to get a specific Count element in an XML variable - xmlUsing hoverIntent with .on or delgate - javascriptHow to check a program in the background if a key or combination is pressed? - c #All Articles