В настоящее время работает в C ++, пытаясь создать класс init, чтобы инициализировать часть поведения в GLFW и GLEW. В основном я перемещаю всю часть настройки в новый класс под названием Init. Init будет иметь методы для выполнения каждой части установки, поэтому я могу просто назвать его функцией run () после создания объекта. Однако я сталкиваюсь с ошибкой компилятора с этим «не может определить, какой экземпляр перегруженной функции» init :: init ». Похоже, что компилятор не может определить, какой конструктор использовать.class Init {
public:
Init(GLuint width, GLuint height, GLchar* vertexShaderSource, GLchar* fragmentShaderSource);
void run();
void setHeight(GLuint height);
void setWidth(GLuint width);
GLuint getHeight();
GLuint getWidth();
GLFWwindow* getWindow(){return this->fwindow;}
void createWindow();
void setKeyCallback(GLFWwindow* window);
void setViewportSettings();
int setVertexShaderSettings();
int setFragmentShaderSettings();
int glLinkShaders();
private:
GLuint fwidth;
GLuint fheight;
GLFWwindow* fwindow;
GLuint fvertexShader;
GLuint ffragmentShader;
GLuint shaderProgram;
GLchar* fvertexShaderSource;
GLchar* ffragmentShaderSource;
GLint fsuccess;
GLchar finfoLog[512];
};
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
< /code>
init.cpp
#include "../src/Init.h"
#include "../include/GL/glew.h"
#include "../include/GLFW/glfw3.h"
#include
Init::Init(GLuint width, GLuint height, GLchar* vertexShaderSource, GLchar* fragmentShaderSource){
this->fwidth = width;
this->fheight = height;
this->fvertexShaderSource = vertexShaderSource;
this->ffragmentShaderSource = fragmentShaderSource;
}
void Init::run(){
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
}
void Init::setHeight(GLuint height){
this->fheight = height;
}
void Init::setWidth(GLuint width){
this->fwidth = width;
}
GLuint Init::getHeight(){return this->fheight;}
GLuint Init::getWidth(){return this->fwidth;}
//GLFWwindow* getWindow(){return this->fwindow;}
void Init::createWindow(){
this->fwindow = glfwCreateWindow(this->fwidth, this->fheight, "Ayite's UI Thingy", nullptr, nullptr);
glfwMakeContextCurrent(this->getWindow());
}
void Init::setKeyCallback(GLFWwindow* window){
glfwSetKeyCallback(window, key_callback);
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
void Init::setViewportSettings(){
int width, height;
glfwGetFramebufferSize(this->getWindow(), &width, &height);
glViewport(0, 0, width, height);
}
int Init::setVertexShaderSettings(){
this->fvertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(this->fvertexShader, 1, &this->fvertexShaderSource, NULL);
glCompileShader(this->fvertexShader);
glGetShaderiv(this->fvertexShader, GL_COMPILE_STATUS, &this->fsuccess);
if (!this>fsuccess)
{
glGetShaderInfoLog(this->fvertexShader, 512, NULL, this->finfoLog);
std::cout ffragmentShader, 1, &this->ffragmentShaderSource, NULL);
glCompileShader(this->ffragmentShader);
// Check for compile time errors
glGetShaderiv(this->ffragmentShader, GL_COMPILE_STATUS, &this->fsuccess);
if (!this->fsuccess)
{
glGetShaderInfoLog(this->ffragmentShader, 512, NULL, this->finfoLog);
std::cout shaderProgram, this->fvertexShader);
glAttachShader(this->shaderProgram, this->ffragmentShader);
glLinkProgram(this->shaderProgram);
// Check for linking errors
glGetProgramiv(this->shaderProgram, GL_LINK_STATUS, &this->fsuccess);
if (!this->fsuccess) {
glGetProgramInfoLog(this->shaderProgram, 512, NULL, this->finfoLog);
std::cout ffragmentShader);
return 0;
}
< /code>
main.cpp
Ошибка происходит здесь: не может определить, какой экземпляр перегруженной функции "init :: init" предназначена в строке 42 < /p>
Init::Init init(WIDTH, HEIGHT, vertexShaderSource, fragmentShaderSource);
< /code>
main.cpp
// GLEW
#define GLEW_STATIC
#include "../include/GL/glew.h"
// GLFW
#include "../include/GLFW/glfw3.h"
#include "../src/Init.h"
#include
// Function prototypes
//void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
// Shaders
const GLchar* vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 position;\n"
"void main()\n"
"{\n"
"gl_Position = vec4(position.x, position.y, position.z, 1.0);\n"
"}\0";
const GLchar* fragmentShaderSource = "#version 330 core\n"
"out vec4 color;\n"
"void main()\n"
"{\n"
"color = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
"}\n\0";
// The MAIN function, from here we start the application and run the game loop
int main()
{
// Init GLFW
//glfwInit();
// Set all the required options for GLFW
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
//glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
Init::Init init(WIDTH, HEIGHT, vertexShaderSource, fragmentShaderSource);
// Create a GLFWwindow object that we can use for GLFW's functions
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", nullptr, nullptr);
glfwMakeContextCurrent(window);
// Set the required callback functions
glfwSetKeyCallback(window, key_callback);
// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions
glewExperimental = GL_TRUE;
// Initialize GLEW to setup the OpenGL Function pointers
glewInit();
// Define the viewport dimensions
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
// Build and compile our shader program
// Vertex shader
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
// Check for compile time errors
GLint success;
GLchar infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout
Подробнее здесь: https://stackoverflow.com/questions/796 ... s-intended
Не может определить, какой экземпляр перегруженной функции "init :: init" предназначен ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение