Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - adamas

Pages: [1]
1
Window / Re: <SOLVED> sf::Window in my own class trow Errors
« on: November 29, 2012, 10:57:03 pm »
Hello,

thanks alot for the advice with the globals. I know, you should not use them, but the logfile for example i want to have global. But i changed some of my stuff and use some pointers and your advice with the .cpp files to initialize them. Now all works fine with the window!  :D

Quote
SFML is 'just' a multimedia library and by far not an engine/framework. ;)
Sorry, my mistake.. but its great anyway :)

Quote
I'm not trying to take away your motivation, but keep in mind that programming a game (specially a 3D game) isn't trivial at all and needs way more than 'a little bit C++' knowledge. At best you get a good book about C++ and read it front to back. :D
I know, a good game needs definitly more than some knowledge. I just want to try and have some fun with openGl and the SFML 2.0. Some cubes jumping around and a working camera... The result should not be a game. Just a window with some rendered stuff in it^^ I just evaluate the code by time. So... no you don't take my motivation away :)

Quote
The solution to it is, don't use global instances, in fact don't use any globals at all, but wrap things into a class, think about a better approach to accessing your window and pass things around with references. ;)
Thanks to you too, it works :)

but now i have a strange crash when closing the window/application. I dont use an ATI-Graphicscard. And it looks like it depends on a pointer, but dont know which one..

2
Window / sf::Window in my own class trow Errors
« on: November 28, 2012, 09:43:39 pm »
First: please dont comment on my bad english. Okay  :P

Hello guys,

im relatively new to SFML. I learn a little bit C++ for myself and found this engine. It is really awesome, THX to the creator!

At the moment i work on a small project, just to understand 3d-programming and i got some cubes and a window and some movements to work. I try to put all my stuff in different classes and now im trying it with sf::Window. I got it into a simple class and can use it in the main() without problems. But when i put it in a global namespace i get a crash:

Unbehandelte Ausnahme bei 0x77c422b2 in grafik_test.exe: 0xC0000005: Zugriffsverletzung beim Schreiben an Position 0x00000004. (Must be Access Violation in English). Maybe anyone have an idea, why it works local but not global?

window.h
/////////////////////////////////////
#ifndef WINDOW_H
#define WINDOW_H
/////////////////////////////////////

#include "structs.h"
#include <SFML/OpenGL.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

class cWindow{
private:
        sColor color;
        unsigned int maxFPS;
        unsigned int width;
        unsigned int height;
        sf::Window window;

public:
        // Konstruktor / Destruktor
        cWindow(void);
        ~cWindow(void);

        // Setter / Getter
        void setColor(float R, float G, float B);
        void setColor(sColor inputColors);
        void setMaxFPS(int fps);
        void setHeight(int newHeight);
        void setWidth(int newWidth);
       
        sColor getColor(void);
        int getMaxFPS(void);
        int getWidth(void);
        int getHeight(void);
        sf::Window* Ref(void);

        // Methoden
        int cWindow::init(void);
        int cWindow::display(void);
        int cWindow::clear(void);
};

#endif
 

window.cpp
#include "window.h"
#include <iostream>

// Konstruktor / Destruktor
cWindow::cWindow(void){
        this->setColor(0.0, 0.0, 0.0);
        this->setMaxFPS(60);
        this->setHeight(450);
        this->setWidth(900);
}
cWindow::~cWindow(void){

}

// Setter / Getter
void cWindow::setColor(float R, float G, float B){
        this->color.R = R;
        this->color.G = G;
        this->color.B = B;
}
void cWindow::setColor(sColor inputColors){
        this->color.R = inputColors.R;
        this->color.G = inputColors.G;
        this->color.B = inputColors.B;
}
void cWindow::setMaxFPS(int fps){
        this->maxFPS = fps;
}
void cWindow::setHeight(int newHeight){
        this->height = newHeight;
}
void cWindow::setWidth(int newWidth){
        this->width = newWidth;
}

sColor cWindow::getColor(void){
        return this->color;
}
int cWindow::getMaxFPS(void){
        return this->maxFPS;
}
int cWindow::getHeight(void){
        return this->height;
}
int cWindow::getWidth(void){
        return this->width;
}
sf::Window* cWindow::Ref(void){
        return &this->window;
}

// Methoden
int cWindow::init(void){
        this->window.setFramerateLimit(this->getMaxFPS());
        this->window.create(sf::VideoMode(this->getWidth(), this->getHeight(), 32), "Grafik Test", sf::Style::Close);

        glEnable(GL_DEPTH_TEST);
        //glClearColor(0.3, 0.4, 0.7, 0.0);
        glClearColor(this->getColor().R, this->getColor().G, this->getColor().B, 0.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        return 0;
}

int cWindow::display(void){
        this->window.display();
        return 0;
}
int cWindow::clear(void){
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        return 0;
}
 

main.cpp
#include "main.h"

using namespace std;

int main(){
        Global::window.init();
        Global::log.write("It works!", 1);

// GAME_LOOP
        while(Engine::Events::running){
                // changes
                // events

                //while(window->getWindow()->pollEvent(Engine::Events::Event) && Engine::Events::running){
                //      Engine::Events::check();
                //}
        }
    return 1;
}
 

globals.h
/////////////////////////////////////
#ifndef GLOBALS_H
#define GLOBALS_H
/////////////////////////////////////

#include "log.h"
#include "camera.h"
#include "window.h"

namespace Global{
        cLog log;
        cCam camera;
        cWindow window;
};
#endif
 

Pages: [1]
anything