<p>As pointed out in the comments, the most straightforward way to do this is to loop over an array of vertices, which is supported by both fixed and programmable pipelines in OpenGL.</p>

<p>The motivation for requesting a fixed pipeline solution in question is simple: that is what the existing code base uses! At the moment, the code base has no means of importing models and the models that do already exist in the code base have been hand coded using a series of fixed pipeline OpenGL function calls.</p>

<p>All things considered, I believe the best workflow (and answer to this question) would be as follows:</p>

<ol>
<li>Export the CAD models to Wavefront OBJ format</li>
<li>Integrate the fixed-pipeline rendering implementation of this <a href="http://www.dhpoware.com/demos/glObjViewer.html" rel="nofollow noreferrer">open-source OBJ viewer</a> into the code base.</li>
</ol>

CC BY-SA 3.0
2018-04-27T12:49:30.413Z
2018-04-27T12:49:30.413Z
mallwright
<p>You can compile it into a </p>

<pre><code>Vertex vertices[] = {{posx, posy, posz, texu, texv, ..}, 
                     {posx, posy, posz, texu, texv, ..}, 
                     //...
                    }
</code></pre>

<p>and then loop over them:</p>

<pre><code>glBegin(GL_TRIANGLES);
for (int i = 0; i &lt; arraycount(vertices); i++){

    glTexCoord2f(vertices[i].texu, vertices[i].texv);
    //... 
    glVertex3f(vertices[i].posx, vertices[i].posy, vertices[i].posz);
}
glEnd();
</code></pre>

<p>Another solution would be to mimic what the modern vertex buffer based solutions do by creating a VertexAttributeLayout struct and setting it up. Then in the loop you interpret the layout struct and interpret the data as needed.</p>

CC BY-SA 3.0
2018-04-24T13:57:43.630Z
This answer is a good start but needs to be expanded a bit. For example, which format is the most appropriate for extracting the vertices information of a model?
mallwright
CC BY-SA 3.0
2018-04-24T14:34:16.087Z
You don't even need to do that. The good old fixed-function GL 1.1 already had vertex arrays. So just issue a `glDrawArrays`. In the same way you can directly transfer the vertex layout into a bunch of `glVertex/Normal/WhateverPointer` calls. Fixed-function doesn't mean no arrays. In fact in this way the question's premise is quite a bit flawed and he can basically use the very same data and layout that he would use in a "modern" programmable pipeline, just with the old pointer functions instead of `glVertexAttribPointer` and with client arrays instead of buffers.
Christian Rau
CC BY-SA 3.0
2018-04-25T11:35:41.377Z
@ChristianRau Perhaps you could add a MWE as part of an alternative answer?
mallwright
CC BY-SA 3.0
2018-04-25T13:41:31.907Z
@allsey87 At the moment the question and its context is a little unclear, though.
Christian Rau
CC BY-SA 3.0
2018-04-24T11:01:22.070Z
2018-04-25T11:43:24.877Z
2018-04-25T11:43:24.877Z
ratchet freak
<p>I have a CAD model in Solidworks (which can be converted to STL, OBJ, STEP , VRML etc.) that I need to render in an old application, which still uses fixed pipeline.</p>

<p>Ideally, I would like to convert my model into a series of <code>glMaterialfv</code>, <code>glBegin</code>, <code>glVertex3f</code>, <code>glEnd</code> commands that I can compile directly into a C library so that I can avoid loading data from an external file. If this approach will be too painful, however, perhaps someone could alternatively suggest an open-source lightweight fixed pipeline model renderer that I can embed into my code.</p>

CC BY-SA 3.0
2018-04-24T09:46:47.167Z
It seems like **fixed-pipeline** and **programmable-pipeline** would be useful tags in this community, is there any reason why they aren't already available?
mallwright
CC BY-SA 3.0
2018-04-24T14:40:46.263Z
The question here is, how much do you *already* know about OpenGL? Do you already know how to render such a model with the modern programmable pipeline? Do you know how to render anything with the old fixed-function pipeline? Or don't you know *anything* about OpenGL?
Christian Rau
CC BY-SA 3.0
2018-04-24T14:41:30.303Z
In the latter case, you might really want to start somewhere lower down the line. And in the former case the question is a little oddly constructed, since the data your model is represented in is quite orthogonal to the whole fixed-funxtion-vs-programmable question and you can pretty much use any universal vertex/index-array represenation. But if you're actually asking how to even draw *anything* in legacy OpenGL, I'm afraid a third-party tutorial would be more appropriate for such a broad question.
Christian Rau
CC BY-SA 3.0
2018-04-26T12:17:24.490Z
why are you doing this? that pre-compiled source file will be just as big as the data file you would otherwise be loading. also, if you want the data linked into your program just to avoid an external file, you can just make static arrays of raw data, no need to pre-compile the GL commands and the data together. it doesn't sound like good program design to me...
atb
CC BY-SA 3.0
2018-04-26T16:04:16.680Z
What do you aim to gain from no disk?
joojaa
<rendering><legacy-opengl>
How to convert a 3D model into an OpenGL fixed pipeline representation
mallwright
# How to convert a 3D model into an OpenGL fixed pipeline representation

(Asked by: username_0 on 2018-04-24)

I have a CAD model in Solidworks (which can be converted to STL, OBJ, STEP , VRML etc.) that I need to render in an old application, which still uses fixed pipeline.

Ideally, I would like to convert my model into a series of `glMaterialfv`, `glBegin`, `glVertex3f`, `glEnd` commands that I can compile directly into a C library so that I can avoid loading data from an external file. If this approach will be too painful, however, perhaps someone could alternatively suggest an open-source lightweight fixed pipeline model renderer that I can embed into my code.

**Tags:** rendering, legacy-opengl

> **Comments:**
> **username_0**: It seems like **fixed-pipeline** and **programmable-pipeline** would be useful tags in this community, is there any reason why they aren't already available?  
> **username_1**: The question here is, how much do you *already* know about OpenGL? Do you already know how to render such a model with the modern programmable pipeline? Do you know how to render anything with the old fixed-function pipeline? Or don't you know *anything* about OpenGL?  
> **username_1**: In the latter case, you might really want to start somewhere lower down the line. And in the former case the question is a little oddly constructed, since the data your model is represented in is quite orthogonal to the whole fixed-funxtion-vs-programmable question and you can pretty much use any universal vertex/index-array represenation. But if you're actually asking how to even draw *anything* in legacy OpenGL, I'm afraid a third-party tutorial would be more appropriate for such a broad question.  
> **username_2**: why are you doing this? that pre-compiled source file will be just as big as the data file you would otherwise be loading. also, if you want the data linked into your program just to avoid an external file, you can just make static arrays of raw data, no need to pre-compile the GL commands and the data together. it doesn't sound like good program design to me...  
> **username_3**: What do you aim to gain from no disk?  

---

## 2 answers

### Answer by username_0 on 2018-04-27. Score: -2 | Accepted answer

As pointed out in the comments, the most straightforward way to do this is to loop over an array of vertices, which is supported by both fixed and programmable pipelines in OpenGL.

The motivation for requesting a fixed pipeline solution in question is simple: that is what the existing code base uses! At the moment, the code base has no means of importing models and the models that do already exist in the code base have been hand coded using a series of fixed pipeline OpenGL function calls.

All things considered, I believe the best workflow (and answer to this question) would be as follows:

1. Export the CAD models to Wavefront OBJ format
2. Integrate the fixed-pipeline rendering implementation of this [open-source OBJ viewer](http://www.dhpoware.com/demos/glObjViewer.html) into the code base.


---

### Answer by username_4 on 2018-04-24. Score: 1

You can compile it into a

```
Vertex vertices[] = {{posx, posy, posz, texu, texv, ..}, 
                     {posx, posy, posz, texu, texv, ..}, 
                     //...
                    }

```

and then loop over them:

```
glBegin(GL_TRIANGLES);
for (int i = 0; i < arraycount(vertices); i++){

    glTexCoord2f(vertices[i].texu, vertices[i].texv);
    //... 
    glVertex3f(vertices[i].posx, vertices[i].posy, vertices[i].posz);
}
glEnd();

```

Another solution would be to mimic what the modern vertex buffer based solutions do by creating a VertexAttributeLayout struct and setting it up. Then in the loop you interpret the layout struct and interpret the data as needed.

> **Comments:**
> **username_0**: This answer is a good start but needs to be expanded a bit. For example, which format is the most appropriate for extracting the vertices information of a model?  
> **username_1**: You don't even need to do that. The good old fixed-function GL 1.1 already had vertex arrays. So just issue a `glDrawArrays`. In the same way you can directly transfer the vertex layout into a bunch of `glVertex/Normal/WhateverPointer` calls. Fixed-function doesn't mean no arrays. In fact in this way the question's premise is quite a bit flawed and he can basically use the very same data and layout that he would use in a "modern" programmable pipeline, just with the old pointer functions instead of `glVertexAttribPointer` and with client arrays instead of buffers.  
> **username_0**: @username_1 Perhaps you could add a MWE as part of an alternative answer?  
> **username_1**: @allsey87 At the moment the question and its context is a little unclear, though.  

---

