1

so i want to render a 2D Curve. The data for this is provided through Blender as an .obj File. I also have an object loader which retrieves succesfully the vertices of the file.

Here is my window/display limits:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0,0);
glutCreateWindow("examplke");
gluOrtho2D(0.0, 600.0, 0.0, 600.0) // Params: Left, right, bottom, top
glutDisplayFunc(renderDisplay);

And my display function:

void renderDisplay() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 1.0);
glBegin(GL_LINE_STRIP);
for (int i = 0; i < vertices.size(); i += 3) {
    glVertex2f(vertices[i], vertices[i+2]);
}
glEnd();
glFlush();

And my .obj file Data:

v -6.010289 0.000000 0.980260
v -5.443917 0.000000 0.413888
v -4.899328 0.000000 0.000000
v 4.899328 0.000000 0.000000
v 5.487484 0.000000 0.326753
v 5.814237 0.000000 0.740641
l 1 2
l 2 3
l 3 4
l 4 5
l 5 6

So the question here is how exactly do i have to transform the vertex data to render my object correctly in relation to my display limits (Example: 600 x 600 Pixel). Im aware i have to do some GL_PROJECTION and GL_MODELVIEW Transformations. But even after reasearching i dont really understand how this can be done. Or might there be a way doing this via the Blender software?

LoveAndMercy
  • 27
  • 1
  • 1
  • 6
  • The coordinates are in range -6 to 6. So try `gluOrtho2D(-10.0, 10.0, -10.0, 10.0)` – Rabbid76 Aug 25 '22 at 08:46
  • Does this apply to every exported .obj? Or where exactly can i define this limits inside of the 3D Software(Blender). In further process i have to work with different 2D Objects that are not know to me – LoveAndMercy Aug 25 '22 at 08:51
  • You need to set the projection depending on the geometry.`gluOrtho2D` defines a 2 dimensional area that is projected onto the viewport. Coordinates in a different range require a different projection. Alternatively you can scale and translate the coordinates. – Rabbid76 Aug 25 '22 at 08:53
  • So checking beforehand the max and min range of the vertices data and limiting the projection with this data, would the best and easiest way here? – LoveAndMercy Aug 25 '22 at 08:57
  • Yes, of course, this is an option. – Rabbid76 Aug 25 '22 at 08:57

1 Answers1

0

You need to set the projection depending on the geometry. gluOrtho2D defines a 2 dimensional area that is projected onto the viewport. Coordinates in a different range require a different projection. The projected area should contain the minimum and maximum of the vertex coordinates.
Your coordinates are in range -6 to 6. So change the projection, e.g.:

gluOrtho2D(0.0, 600.0, 0.0, 600.0);

gluOrtho2D(-10.0, 10.0, -10.0, 10.0);

Alternatively you can scale and translate the coordinates.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174