zee2200

05-29-2016, 10:46 PM

Hey guys, i have a sprite class that will be handling initializing and drawing shapes to the screen but i have a problem with it right now since when i try to draw a circle it scaled properly and it in the right position but it always has a line going to the 0,0 point I'm not sure what exactly is causing this and my only guess would be because i have glOrtho setup as such glOrtho(0, _width, _height, 0, 0, 1). also here's the init function for the circle.

void Sprite::init(int x, int y, int vertNum, float r, Shape shape) {

_vertNum = vertNum;

if (_vboID == 0) {

glGenBuffers(1, &_vboID);

}

std::vector<Vertex> vertexData(_vertNum);

if (shape == Shape::CIRCLE) {

for (int i = 0; i < _vertNum; i++) {

float angle = 2.0 * M_PI * i / _vertNum;

vertexData[i].setPosition(r*cos(i) + x, r*sin(i) + y);

}

}

glBindBuffer(GL_ARRAY_BUFFER, _vboID);

glBufferData(GL_ARRAY_BUFFER, sizeof(float) *vertexData.size(), vertexData.data(), GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);

}

by the way i tried taking the sine and cosine of both i and angle but neither of them work i just ended up using i since it made a full circle with a line but taking the sine and cosine of angle gave me more of a baseball shape.

void Sprite::init(int x, int y, int vertNum, float r, Shape shape) {

_vertNum = vertNum;

if (_vboID == 0) {

glGenBuffers(1, &_vboID);

}

std::vector<Vertex> vertexData(_vertNum);

if (shape == Shape::CIRCLE) {

for (int i = 0; i < _vertNum; i++) {

float angle = 2.0 * M_PI * i / _vertNum;

vertexData[i].setPosition(r*cos(i) + x, r*sin(i) + y);

}

}

glBindBuffer(GL_ARRAY_BUFFER, _vboID);

glBufferData(GL_ARRAY_BUFFER, sizeof(float) *vertexData.size(), vertexData.data(), GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);

}

by the way i tried taking the sine and cosine of both i and angle but neither of them work i just ended up using i since it made a full circle with a line but taking the sine and cosine of angle gave me more of a baseball shape.