E
E
Evgeny Petryaev2019-09-16 12:57:52
OOP
Evgeny Petryaev, 2019-09-16 12:57:52

What is the best way to pass data from class to class?

There is such a class

//#include "FileReader.h"
struct Image
{
  float**TextureCoordinats;
  float**VertexCoordinats;
  unsigned int*IndexTexture;
  std::string *Name;
  int *number;
};
 class Scene1
{
public:
  Scene1(void);
  void LoadImage(const ILstring path);
  void ShowWelcome(bool show);
  void EnableTexture(float*texcoor, float*vercoor);
  int FindTexture(std::string name);
  ~Scene1();
  unsigned char*copyData;
  static const int CountTexture = 53;//40
  Image *image;
  int CountIndexTexture;
};

and there is a method
void Scene1::LoadImage(const ILstring path)
{
...
  copyData = ilGetData();
...
  glGenTextures(1, &image->IndexTexture[CountIndexTexture]);
...
  glBindTexture(GL_TEXTURE_2D, image->IndexTexture[CountIndexTexture]);
  ...
  gluBuild2DMipmaps(GL_TEXTURE_2D, type, width, height, type, GL_UNSIGNED_BYTE, copyData);
 ...
  CountIndexTexture++;
};

it is necessary for the scene class to receive data from this method, which I plan to place in another FileReader class, how to transfer data from the FileReader class to the Scene class? copyData or even image data, here is a sketch for simplicity
#include "FileReader.h"
class Scene
{
...
FileReader*filereader;
...
}
void Scene1::ShowWelcome(bool show)
{
  ...
  int numb = FindTexture("welcome",filereader->getimagetexture());
  glBindTexture(GL_TEXTURE_2D, filereader->getimagetexture(IndexTexture[numb]));
  EnableTexture(filereader->getimagetexturecoordinats(TextureCoordinats[numb]), filereader->getimagevertexcoordinats(VertexCoordinats[numb]);
        ...
}

And throw LoadImage() and other properties into FileReader
class FileReader
{
 ...
 LoadImage(const ILstring path);
 unsigned char*copyData;
 ...
}
void FileReader::LoadImage(const ILstring path)
{
...
  copyData = ilGetData();
...
  glGenTextures(1, &image->IndexTexture[CountIndexTexture]);
...
  glBindTexture(GL_TEXTURE_2D, image->IndexTexture[CountIndexTexture]);
  ...
  gluBuild2DMipmaps(GL_TEXTURE_2D, type, width, height, type, GL_UNSIGNED_BYTE, copyData);
 ...
  CountIndexTexture++;
};

, or is it possible in some other way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question