OPENGL Help Finding Error

I amm following the tutorial and it works perfectly for him, I understand everything but somehow the code does not work. This time I got errors. So here are they are.

Errors:Error 1 error C2065: 'display' : undeclared identifier
Error 2 error C2228: left of '.IsClosed' must have class/struct/union
error C2761: 'bool Display::IsClosed(void)' : member function redeclaration not allowed

-----main.cpp----

#include <iostream>
#include "Display.h"
#include <GL\glew.h>

int main ()
{
Display::Display (800, 600, "Hello World");
while(!display.IsClosed)
{
glClearColor(0.0f, 0.15f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
display.Update();
}


return 0;

}



-----display.h------



#ifndef DISPLAY_H
#define DISPLAY_H
#include <SDL2/SDL.h>
#include <string>

class Display
{
public:
Display(int width, int height, const std::string& title);
void Update();
bool IsClosed();
virtual ~Display();




protected:
private:
Display(const Display& other){}
Display& operator=(const Display& other){}

SDL_Window* m_window;
SDL_GLContext m_glContext;
bool m_isClosed;
};

#endif // DISPLAY_H


-------display.cpp------

#include "display.h"
#include <iostream>
#include <GL\glew.h>



Display::Display(int width, int height, const std::string& title)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); // The quality of each Prime color.
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);//8 is the best.
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);//Because we want specific number of memoryfor each so 8*4
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //Gives space for 2 windows

m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
m_glContext = SDL_GL_CreateContext(m_window);//creates context so OS is influencing GPU which is drawing using Opengl.

GLenum status = glewInit();//starts glew and it searches OS for OpenGL we support.

if(status != GLEW_OK)
{
std::cerr << "Glew failed to initialize!" << std::endl;
}

m_isClosed = false;
}

Display::~Display()
{
SDL_GL_DeleteContext(m_glContext);//going backwards and destroying everything since we did gl context last ^
SDL_DestroyWindow(m_window);//before that, this.
SDL_Quit();
}

bool Display::IsClosed();
{
return m_isClosed;
}


void Display::Update()
{
SDL_GL_SwapWindow(m_window);

SDL_Event e;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
m_isClosed = true;

}
}

From the issues you're describing, it would seem a C++ language tutorial would be more advantageous for you than an OpenGL tutorial, since all of those issues are simple language/syntax misunderstandings.

1
2
3
4
int main ()
{
    Display display(800, 600, "Hello World");
    while(!display.IsClosed())


You need to drop the semi-colon after the prototype in your definition of Display::IsClosed
Topic archived. No new replies allowed.