Cojocari Iurii Cojocari Iurii - 3 months ago 9
C++ Question

Function to draw a rectangle with C++

I try to write a function that generates a rectangle which takes as input the following information:

topLeftPoint, and (width and height) of the desired rectangle. As the result it should return the coresponding vertices. I'm using the

OpenGL
coordinate system.

topLeftPoint can be a simple struct of two
ints
or
Vec2
.

Here is an example of how I try to solve this task:
example

float verticesOfRectangle[] =
{
in.x(), in.y(),
in.x(), in.y() - h,
in.x() + w, in.y()-h,
in.x() + w, in.y(),
}


What is wrong with my code? My final shapes doesn't look like a rectangle. It looks more likes this: final shape

Answer

Guessing, reorder them like this:

float verticesOfRectangle[] =   
{  
   in.x(), in.y() - h,  
   in.x() + w, in.y() - h,  
   in.x(), in.y(),  
   in.x() + w, in.y(),  
}