0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – allsey87 Apr 24 '18 at 9:46
  • 1
    $\begingroup$ 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? $\endgroup$ – Christian Rau Apr 24 '18 at 14:40
  • $\begingroup$ 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. $\endgroup$ – Christian Rau Apr 24 '18 at 14:41
  • $\begingroup$ 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... $\endgroup$ – atb Apr 26 '18 at 12:17
  • $\begingroup$ What do you aim to gain from no disk? $\endgroup$ – joojaa Apr 26 '18 at 16:04
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – allsey87 Apr 24 '18 at 13:57
  • $\begingroup$ 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. $\endgroup$ – Christian Rau Apr 24 '18 at 14:34
  • $\begingroup$ @ChristianRau Perhaps you could add a MWE as part of an alternative answer? $\endgroup$ – allsey87 Apr 25 '18 at 11:35
  • $\begingroup$ @allsey87 At the moment the question and its context is a little unclear, though. $\endgroup$ – Christian Rau Apr 25 '18 at 13:41
-2
$\begingroup$

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 into the code base.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.