Advertisement

Loading Bezier Patches/Vertices Internally Rather than Externally

Started by February 11, 2025 06:16 PM
1 comment, last by cjordan1983 6 days, 9 hours ago

Hello, 

I have an OpenGL in C++ tree traversal program that loads a teapot, a teacup, and a teaspoon through the use of Bezier patches and vertices.  This method of reading in the data from these .patches and .vertices files is not something I am wanting to do any longer.  The biggest reason is that the compiled .exe file still requires those files in the same folder in order to run.  What I want to do, and am already very very close to accomplishing, is simply storing the patch and vertice data inside of individual header files and then simply reference the header files at the top of the program.  Should be easy, and for the most part it technically works!  For whatever reason, when I toggle from the main screen to the wireframe, the wireframe is stretching the vertice points at the teapot, the teacup and the teaspoon and I have no idea why.  Please see the following images that I've attached:

Again, for whatever reason, everything else works fine in the normal scene, it's just when I toggle wireframe mode that it stretches the points of the three objects.  This has me wondering if there's something wrong with the wireframe portion of the code, but I cannot figure out what it is.  Here's my function for reading in the data externally from the files:

void readData(char* pointfile, char* patchfile, patch* myarr) {
  ifstream points(pointfile);
  ifstream patches(patchfile);
  if(!points.is_open() || !patches.is_open()) {
     cerr << "Failed to open file. Press enter to quit:";
     char throwaway[2];
     cin.getline(throwaway, 1);
     exit(1);
  }
  
  int numpoints, numpatches;
  points >> numpoints;
  patches >> numpatches;
  GLfloat tp[numpoints][3];
  for(int i = 0; i < numpoints; i++) {
     for(int j = 0; j < 3; j++) {
        points >> tp[i][j];
     }
     if(points.rdstate()) {
        cerr << "Failure reading " << pointfile << ". Press enter to quit: ";
        char throwaway[2];
        cin.getline(throwaway, 1);
        exit(1);
     }
  }
  int tempint;
  for(int i = 0; i < numpatches; i++) {
     for(int j = 0; j < 4; j++) {
        for(int k = 0; k < 4; k++) {
           patches >> tempint;
           for(int l = 0; l < 3; l++) {
              myarr[i][j][k][l] = tp[tempint - 1][l];
           }
        }
     }
  }
  if(points.rdstate()) {
     cerr << "Failure reading " << pointfile << ". Press enter to quit:";
     char throwaway[2];
     cin.getline(throwaway, 1);
     exit(1);
  }
}

and then the node traversal portion of the program reads in the teapot data like this:

teapot_node.f = teapot;
teapot_node.child = NULL;
teapot_node.sibling = &teacup_node;
readData("teapot.vertices", "teapot.patches", teapot_data);

That's the version that works perfectly, but is reading in the files from a required external file, which is not what I want anymore.  I need to be able to read everything internally from a header file.  

Ergo, this is my preferred way of reading in the data internally from a header file but is stretching the vertice/patch data:

void loadTeapotData(GLfloat myarr[32][4][4][3]) {
   int numpatches = 32;
   for (int i = 0; i < numpatches; i++) {
       for (int j = 0; j < 4; j++) {
           for (int k = 0; k < 4; k++) {
               int index = teapot_patches[i][j * 4 + k]; 
               for (int l = 0; l < 3; l++) {
                   myarr[i][j][k][l] = teapot_vertices[index][l];
               }
           }
       }
   }
}

and then the node section again, only the last line being altered:

teapot_node.f = teapot;
teapot_node.child = NULL;
teapot_node.sibling = &teacup_node;
loadTeapotData(teapot_data); 
 

and then I initialize the teapot in my main function:

loadTeapotData(teapot_data);

and the vertice and patch data is referenced within my header file which I include at the top for each drawn object:

#include "teapot_data.h"

I'm happy to provide my teapot header file for reference.  I figured you may want to see it, unless you can already see an issue with what I've provided above.  Please help.  I know I have to be close on getting this resolved, but the problem still seems to be at arms length.  I appreciate it.

Happy Valentines Day! Bumping this because it's been a little over 3 days and no response. :/ I see the other topics of OpenGL so I know I'm posting in the right space. Are there no users who have used Bezier patches before? This website has existed since 1999 so I can't be the first person needing assistance with this. Here is a Google Drive link to my Bezier .patches & .vertices files along with my header file for the Teapot if you need to reference that. If no one knows what my issue is relating to, can you recommend another online location to assist? Thanks!

Advertisement