L
Lslkaiaoqlaoaoa
Guest
I get error "argument of type "int" is incompatible with parameter type "int*""
How to fix?
My code:
enginec.cpp: I have error happening at line 38.
#include "engine.h"
#include <iostream>
using namespace std;
int Engine::SWIDTH = 1024;
int Engine::SHEIGHT = 768;
GLFWwindow* Engine::window = NULL;
Engine::Engine() {
}
Engine::~Engine() {
}
bool Engine::init(char* windowTitle) {
if (!glfwInit()) {
cout << "Error initializing GLFW" << endl;
return false;
}
window = glfwCreateWindow(SWIDTH, SHEIGHT, windowTitle, NULL, NULL);
if (window == NULL) {
cout << "Error initializing and creating window" << endl;
return false;
}
// GLFW Setup
glfwMakeContextCurrent(window);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glfwSwapInterval(1);
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
int xPos = (mode->width - SWIDTH) / 2;
int yPos = (mode->height - SHEIGHT) / 2;
glfwGetWindowPos(window, xPos, yPos);
// GL Setup
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -10, 10);
glDepthRange(-10, 10);
glMatrixMode(GL_MODELVIEW);
// Alpha Blending
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return true;
}
void Engine::update() {
glfwPollEvents();
}
void Engine::render() {
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window);
}
engine.h: I dont have any error here.
#ifndef GAME_ENGINE
#define GAME_ENGINE
#include "GLFW\glfw3.h"
#include <iostream>
using namespace::std;
#pragma comment(lib, "opengl32.lib")
class Engine {
public:
static int SWIDTH;
static int SHEIGHT;
Engine();
~Engine();
bool init(char* windowTitle);
void update();
void render();
private:
static GLFWwindow* window;
};
#endif
main.cpp (I get sometimes error "argument of type const char* is incompatible with parameter type char*" but I fixed it. If there's anything wrong with it please tell me: happens on 13th line when I delete (char*)):
#include "engine.h"
#include <iostream>
using namespace std;
int main() {
cout << "Debug.Test" << endl;
while (true) {
Engine engine;
engine.init((char*)"Game");
engine.update();
engine.render();
}
return 0;
}
Continue reading...
How to fix?
My code:
enginec.cpp: I have error happening at line 38.
#include "engine.h"
#include <iostream>
using namespace std;
int Engine::SWIDTH = 1024;
int Engine::SHEIGHT = 768;
GLFWwindow* Engine::window = NULL;
Engine::Engine() {
}
Engine::~Engine() {
}
bool Engine::init(char* windowTitle) {
if (!glfwInit()) {
cout << "Error initializing GLFW" << endl;
return false;
}
window = glfwCreateWindow(SWIDTH, SHEIGHT, windowTitle, NULL, NULL);
if (window == NULL) {
cout << "Error initializing and creating window" << endl;
return false;
}
// GLFW Setup
glfwMakeContextCurrent(window);
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glfwSwapInterval(1);
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
int xPos = (mode->width - SWIDTH) / 2;
int yPos = (mode->height - SHEIGHT) / 2;
glfwGetWindowPos(window, xPos, yPos);
// GL Setup
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -10, 10);
glDepthRange(-10, 10);
glMatrixMode(GL_MODELVIEW);
// Alpha Blending
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
return true;
}
void Engine::update() {
glfwPollEvents();
}
void Engine::render() {
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window);
}
engine.h: I dont have any error here.
#ifndef GAME_ENGINE
#define GAME_ENGINE
#include "GLFW\glfw3.h"
#include <iostream>
using namespace::std;
#pragma comment(lib, "opengl32.lib")
class Engine {
public:
static int SWIDTH;
static int SHEIGHT;
Engine();
~Engine();
bool init(char* windowTitle);
void update();
void render();
private:
static GLFWwindow* window;
};
#endif
main.cpp (I get sometimes error "argument of type const char* is incompatible with parameter type char*" but I fixed it. If there's anything wrong with it please tell me: happens on 13th line when I delete (char*)):
#include "engine.h"
#include <iostream>
using namespace std;
int main() {
cout << "Debug.Test" << endl;
while (true) {
Engine engine;
engine.init((char*)"Game");
engine.update();
engine.render();
}
return 0;
}
Continue reading...