I'm trying to create a class that will describe a particular object I'm trying to render to the screen. I have a Shaders, Mesh, and Texture object that I have been running in main() that is working fine. All it does now is draw an image to the screen.
But when I put those objects in a class called Entity and try to render with it, it doesn't draw the image.
Main code:
int main(int argc, char*argv[]) {
Display display;
display.init(); //Sets up SDL and glew
Shaders shaders("basicShader");
Mesh mesh(shaders.getProgram());
Texture texture("kitten.png");
Entity entity;
//Loop stuff
bool quit = false;
SDL_Event e;
double frameCounter = 0;
double time = SDL_GetTicks();
while (!quit) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
quit = true;
}
if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_ESCAPE)
quit = true;
}
}
++frameCounter;
if (SDL_GetTicks() - time >= 500) {
std::cout << "FPS: " << frameCounter / ((SDL_GetTicks() - time) / 1000) << std::endl;
frameCounter = 0;
time = SDL_GetTicks();
}
// Clear the screen to black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
mesh.draw();
//entity.render();
// Swap buffers
display.render();
}
mesh.~Mesh();
entity.~Entity();
display.~Display();
return 0;
}
Entity header:
#pragma once
#include "Mesh.h"
#include "Shaders.h"
#include "Texture.h"
class Entity
{
public:
Entity();
void render();
~Entity();
private:
Mesh mesh;
Shaders shaders;
Texture texture;
};
Entity class code:
#include "Entity.h"
Entity::Entity() {
shaders = Shaders("basicShader");
mesh = Mesh(shaders.getProgram());
texture = Texture("kitten.png");
}
void Entity::render() {
mesh.draw();
}
Entity::~Entity() {
mesh.~Mesh();
}
This code works when mesh.draw() is uncommented and entity.render() IS commented in main(), but not the other way around. I can post code from headers and other classes if necessary.