by Anonymous » 12 Feb 2025, 04:20
Berücksichtigen Sie den folgenden Code (es wird OpenGL verwendet, aber darum geht es nicht, worum es in meiner Frage geht): < /p>
#include
#include
#include
#include
using std::string;
...
//Example func for loading content of external file
string load(string src) {
std::ifstream file(src);
if (file.fail()) {
output("FILE", "Failed to access content of file at location " + string(src), 1);
}
string content;
while (!file.eof()) {
char character;
file.get(character);
content.push_back(character);
}
content.pop_back();
return content;
};
unsigned int compileShader() {
// Create shader
unsigned int shader;
shader = glCreateShader(type);
string codeString = load(src); // Load shader from file here
const char* code = codeString.c_str(); // Convert to C string (needed in further computations)
// What does the code look like?
std::cout
Die Funktion compileshader () lädt somit den Inhalt einer externen Datei, die in GLSL geschrieben wurde ein Argument für die GL -Funktion glhadersource (). Und es funktioniert gut. < /P>
konzentriertstring codeString = load(src); // Load shader from file here
const char* code = codeString.c_str(); // Convert to C string
// What does the code look like?
std::cout
const char* code = load(src).c_str(); // Load shader from file and convert to C string
// What does the code look like?
std::cout
Was verhindert, dass es funktioniert? Was sind die zugrunde liegenden Mechaniker dahinter? Vielen Dank für Ihre Antworten. Ich bin in C ++ relativ neu, daher könnte es wirklich einfach sein, nur ich weiß nicht, wo ich genau nach einer Antwort suchen kann.
Berücksichtigen Sie den folgenden Code (es wird OpenGL verwendet, aber darum geht es nicht, worum es in meiner Frage geht): < /p>
#include
#include
#include
#include
using std::string;
...
//Example func for loading content of external file
string load(string src) {
std::ifstream file(src);
if (file.fail()) {
output("FILE", "Failed to access content of file at location " + string(src), 1);
}
string content;
while (!file.eof()) {
char character;
file.get(character);
content.push_back(character);
}
content.pop_back();
return content;
};
unsigned int compileShader() {
// Create shader
unsigned int shader;
shader = glCreateShader(type);
string codeString = load(src); // Load shader from file here
const char* code = codeString.c_str(); // Convert to C string (needed in further computations)
// What does the code look like?
std::cout
Die Funktion compileshader () lädt somit den Inhalt einer externen Datei, die in GLSL geschrieben wurde ein Argument für die GL -Funktion glhadersource (). Und es funktioniert gut. < /P>
konzentriertstring codeString = load(src); // Load shader from file here
const char* code = codeString.c_str(); // Convert to C string
// What does the code look like?
std::cout
const char* code = load(src).c_str(); // Load shader from file and convert to C string
// What does the code look like?
std::cout
Was verhindert, dass es funktioniert? Was sind die zugrunde liegenden Mechaniker dahinter? Vielen Dank für Ihre Antworten. Ich bin in C ++ relativ neu, daher könnte es wirklich einfach sein, nur ich weiß nicht, wo ich genau nach einer Antwort suchen kann.