• Advertisement

c4c0d3m0n

Member
  • Content count

    275
  • Joined

  • Last visited

Community Reputation

100 Neutral

About c4c0d3m0n

  • Rank
    Member
  1. Hello The rule of thumb on destructors, copy constructors and assignment operators is that if you need one of them, you probably need all three. Hence, I've implemented them in my texture class, but I am not sure whether I have done it the right way ®. Never too shy to learn more about c++ do's and don't's, I hoped I might get some responses on my snippet of code here: [code]class Image { public: Image(int width, int height) : width(width), height(height), pixels(new Color[width * height]) {} Image(const Image& other); ~Image() {delete[] pixels;} const Image& operator= (Image other); int get_width() const {return width;} int get_height() const {return height;} const Color& get_pixel(int x, int y) const {return pixels[x + width * y];} void set_pixel(int x, int y, Color c) {pixels[x + width * y] = c;} private: int width, height; Color *pixels; };[/code] [code]Image::Image(const Image& other) : width(other.width), height(other.height), pixels(new Color[other.width * other.height]) { std::copy(other.pixels, other.pixels + (width * height), pixels); } const Image& Image::operator= (Image other) { std::swap(pixels, other.pixels); std::swap(width, other.width); std::swap(height, other.height); return *this; }[/code] This code has not been tested thoroughly yet, and I've ran into some infinite loops in my programming before. I've suspected this snippet to be at fault, so no guarantees on it working...
  2. opengl matrix magics

    Alright, what I meant by magic was the whole idea of having matrices in general. I don't really understand what a matrix "represents", and why I need more than one of them. When I call SDL_GL_SwapBuffers() and glFlush(), what effects do the various matrices have on what is displayed on screen? When I call initializing functions, what am I given?
  3. opengl matrix magics

    Hello all I've been trying to teach myself OpenGL graphics programming. It's quite a change from what I was used to with SDL. Although I am able to copy the code and understand most of it from various tutorials, there is something bothering me when I'm trying to do things myself. Namely: I would like to get a more thorough understanding of this Matrix stuff. My understanding is that there are multiple matrices (Projection, Modelview, etc) and that there are certain operations I can do. I was wondering whether there are any good (free) resources where the basics of OpenGL are explained. What happens when I call glOrtho2D, glFrustum, glViewport... What use is pushing and popping matrices... These are just some examples, I hope you catch my drift.
  4. Never learn games programming!

    Quote:Original post by CodaKiller As for the DirectX vs OpenGL part I really don't see the point in making a cross platform game since windows holds 90% of the market and the only real market for indie games is on steam which only works on windows. It's an insane amount of work to make a game function on more then one platform, not many large corporations even do this because it requires you to almost rewrite everything even if you used cross platform libraries. Just do what works for what you want! This is only interesting if you plan on releasing something that will actually be interesting to that big chunk of gamers. You'd be surprised how well indie games work on platforms like mac and linux (e.g. World of Goo). Most indie games won't be interesting for 89% of the market that windows holds anyway. I say look at your own needs and requirements. If you only use Windows anyway and your friends do too, then just develop with either DirectX or OpenGL, whatever floats your boat. If you'd rather not get all specific on one of those two lower level libraries, get an engine like Ogre3D for example and start programming an actual game without worrying about how the things work behind the scenes too much. Added benifit of using an engine is that when you do start using the lower level libraries, you'll have a good idea of what functionality you need to create. Personally, I started with SDL. It wasn't too complicated, provided only 2D stuff which was just what I wanted to get my foot down in programming in general. Now I started learning some OpenGL, because the 2D capabilities of SDL were too simple and I want to learn something new too. Seeing I use Linux OpenGL was a natural choice for me. Anyhow, just go with whatever would work for you. There is things to say for all sides of the argument. If you'd rather put together a cool game for friends to see right now, just get a ready engine and go wild. If you'd rather create some tech demos and improve your programming in general to maybe work on a proper game later, go for something more low level.
  5. Hello all I'm trying to find out how to switch between SDL and OpenGL for drawing. In my game, I would like to use simple SDL blitting for the main menu, and then nice accelerated OpenGL for the gameplay. I threw together some code to try if it would work, but what I tried here clearly didn't work. What happens is that the following code compiles fine (g++ foo.cpp -lSDL -lGL -lGLU) but when I try to switch from SDL to OpenGL the program just crashes and SDL_GetError() isn't telling me anything... #include <SDL/SDL.h> #include <SDL/SDL_opengl.h> #include <iostream> const int QUIT_PLZ = 0 << 1; int sdl() { // Initialization SDL_Surface* screen = NULL; screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE); if (!screen) { std::cout << SDL_GetError(); return QUIT_PLZ; } SDL_WM_SetCaption("SDL", NULL); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0x10, 0xDD, 0x12)); SDL_Flip(screen); // Vars SDL_Event event; bool done = false; // Main loop while (!done) { // Event polling while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) return QUIT_PLZ; if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) { done = true; } } // Sleep SDL_Delay(10); } return 0; } int opengl() { // Initialization if (!SDL_SetVideoMode(800, 600, 32, SDL_OPENGL)) { std::cout << SDL_GetError(); return QUIT_PLZ; } SDL_WM_SetCaption("SDL + OpenGL", NULL); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat height = (GLfloat) SDL_GetVideoSurface()->h; GLfloat width = (GLfloat) SDL_GetVideoSurface()->w; gluPerspective(45.0f, width / height, 0.1f, 100.0f); // Vars SDL_Event event; bool done = false; GLfloat rotation = 0.0f; // Main loop while (!done) { rotation += 1.0f; // Event polling while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) return QUIT_PLZ; if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) { done = true; } } // OpenGL magix glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-2.0f, 0.0f, -8.0f); glRotatef(rotation, 0.2f, 0.7f, 0.0f); glBegin(GL_TRIANGLES); glColor3f(1, 0, 0); glVertex3f(-1, -1, 1); glColor3f(0, 1, 0); glVertex3f( 1, 1, 1); glColor3f(0, 0, 1); glVertex3f(-1, 1, -1); glColor3f(1, 0, 0); glVertex3f( 1, 1, 1); glColor3f(0, 1, 0); glVertex3f(-1, -1, 1); glColor3f(0, 0, 1); glVertex3f( 1, -1, -1); glColor3f(1, 0, 0); glVertex3f(-1, 1, -1); glColor3f(0, 1, 0); glVertex3f( 1, -1, -1); glColor3f(0, 0, 1); glVertex3f(-1, -1, 1); glColor3f(1, 0, 0); glVertex3f( 1, -1, -1); glColor3f(0, 1, 0); glVertex3f(-1, 1, -1); glColor3f(0, 0, 1); glVertex3f( 1, 1, 1); glEnd(); glLoadIdentity(); glTranslatef(2.0f, 0.0f, -8.0f); SDL_GL_SwapBuffers(); glFlush(); // Sleep SDL_Delay(10); } return 0; } int main() { SDL_Init(SDL_INIT_EVERYTHING); if (sdl() == QUIT_PLZ) { SDL_Quit(); return 0; } if (opengl() == QUIT_PLZ) { SDL_Quit(); return 0; } if (sdl() == QUIT_PLZ) { SDL_Quit(); return 0; } SDL_Quit(); return 0; } I was hoping someone could clear me up on how to do this, or maybe tell me off because it's a bad idea all together to start with. If so, I'd be open for alternatives. I guess in the end I could even write the menu in OpenGL, but I'm more familiar with SDL and I would like to throw together something showable now and then program the actual game behind it later.
  6. sdl & opengl

    What I did to learn SDL is follow Lazy Foo's tutorials. The last tutorial explains how to set up SDL with OpenGL rendering. Then, I just started doing some of NeHe's tutorials, ignoring the windowing code and just looking at the drawing code. Most of his tutorials also provide a link at the bottom to an archive with the alternative tutorial code written using SDL+OpenGL.
  7. [C++] [OpenGL + SDL] Can't get lights to work

    Hmm alright, now that seems to enable lighning, but now the colours on my tetrahedron are gone! It just appears white (with correct light effects), however it used to be nicely coloured as it was taught in one of the first tutorials... How can I regain this colour?
  8. Hey all, I'm working through NeHe's tutorials, they are really great. I'm using SDL for window management because I'm used to it and because I use Linux and it seemed like the most easy way to do it. However, I can't get my code to work... Could someone please look if they can find any big flaws? The textured cube and the coloured tetrahedron show up and rotate as planned, but aren't lit at all, they are just fully lit as if I never wrote the code for the lights. #include <SDL/SDL.h> #include <SDL/SDL_opengl.h> int main(int argc, char** argv) { // Initialization SDL_Init(SDL_INIT_EVERYTHING); SDL_SetVideoMode(800, 600, 32, SDL_OPENGL); SDL_WM_SetCaption("OpenGL Lights", NULL); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat height = (GLfloat) SDL_GetVideoSurface()->h; GLfloat width = (GLfloat) SDL_GetVideoSurface()->w; gluPerspective(45.0f, width / height, 0.1f, 100.0f); // Lights GLfloat ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat lightpos[] = { 0.0f, 0.0f, 2.0f, 1.0f }; glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_POSITION, lightpos); glEnable(GL_LIGHT1); // Vars SDL_Event event; bool done = false; GLfloat xrot = 0.0f; GLfloat yrot = 0.0f; GLfloat zrot = 0.0f; GLuint texture; { SDL_Surface* sfc = SDL_LoadBMP("nehe.bmp"); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, 3, sfc->w, sfc->h, 0, GL_BGR, GL_UNSIGNED_BYTE, sfc->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); SDL_FreeSurface(sfc); } // Main loop while (!done) { // Event polling while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) done = true; if (event.type == SDL_KEYUP) { done = true; } } // OpenGL magix glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-2.0f, 0.0f, -8.0f); glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); glEnable(GL_TEXTURE_2D); glColor3f(1, 1, 1); glBindTexture(GL_TEXTURE_2D, texture); glBegin(GL_QUADS); // Bottom glNormal3f(0, -1, 0); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1, -1, 1); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1, -1, -1); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1, -1, -1); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, 1); // Front glNormal3f(0, 0, 1); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1, 1, 1); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1, -1, 1); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1, -1, 1); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, 1, 1); // Top glNormal3f(0, 1, 0); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1, 1, -1); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1, 1, 1); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1, 1, 1); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, 1, -1); // Back glNormal3f(0, 0, -1); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1, -1, -1); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1, 1, -1); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1, 1, -1); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, -1); // Left glNormal3f(-1, 0, 0); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1, 1, -1); glTexCoord2f(1.0f, 1.0f); glVertex3f(-1, -1, -1); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1, -1, 1); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, 1, 1); // Right glNormal3f(1, 0, 0); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1, -1, -1); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1, 1, -1); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1, 1, 1); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, 1); glEnd(); glDisable(GL_TEXTURE_2D); glLoadIdentity(); glTranslatef(2.0f, 0.0f, -8.0f); glRotatef(xrot, 1.0f, 0.0f, 0.0f); glRotatef(yrot, 0.0f, 1.0f, 0.0f); glRotatef(zrot, 0.0f, 0.0f, 1.0f); glBegin(GL_TRIANGLES); glNormal3f(-1, 1, 1); glColor3f(1, 0, 0); glVertex3f(-1, -1, 1); glColor3f(0, 1, 0); glVertex3f( 1, 1, 1); glColor3f(0, 0, 1); glVertex3f(-1, 1, -1); glNormal3f(1, -1, 1); glColor3f(1, 0, 0); glVertex3f( 1, 1, 1); glColor3f(0, 1, 0); glVertex3f(-1, -1, 1); glColor3f(0, 0, 1); glVertex3f( 1, -1, -1); glNormal3f(-1, -1, -1); glColor3f(1, 0, 0); glVertex3f(-1, 1, -1); glColor3f(0, 1, 0); glVertex3f( 1, -1, -1); glColor3f(0, 0, 1); glVertex3f(-1, -1, 1); glNormal3f(1, 1, -1); glColor3f(1, 0, 0); glVertex3f( 1, -1, -1); glColor3f(0, 1, 0); glVertex3f(-1, 1, -1); glColor3f(0, 0, 1); glVertex3f( 1, 1, 1); glEnd(); SDL_GL_SwapBuffers(); glFlush(); // Rotate variables increments xrot += 1.0f; yrot += 0.7f; zrot += 0.6f; // Sleep SDL_Delay(10); } return 0; } Thanks
  9. Indeed, moving the specializations to a seperate sourcefile was the solution. Thank you very much. edit After some rethinking, I've come to the conclusion my approach really beats the purpose of templates here, because I end up redefining each function for each resource type anyway. I've changed it to Resources::get_image() and the likes. [Edited by - c4c0d3m0n on April 8, 2009 2:10:19 PM]
  10. #ifndef RESOURCES_H_INCLUDED #define RESOURCES_H_INCLUDED #include <map> #include <string> #include <SDL/SDL.h> #include <SDL/SDL_mixer.h> #include <iostream> /** * The Resources class holds some specialized types of resources, allowing for * easy maintaining. */ class Resources { private: std::map<std::string, SDL_Surface*> surfaces; std::map<std::string, Mix_Chunk*> sounds; public: template<class T> void load(std::string, std::string); template<class T> void unload(std::string); template<class T> T get(std::string); template<> void load<SDL_Surface*>(std::string, std::string); template<> void unload<SDL_Surface*>(std::string); template<> SDL_Surface* get<SDL_Surface*>(std::string); template<> void load<Mix_Chunk*>(std::string, std::string); template<> void unload<Mix_Chunk*>(std::string); template<> Mix_Chunk* get<Mix_Chunk*>(std::string); }; template<> void Resources::load<SDL_Surface*>(std::string file, std::string id) { SDL_Surface* toLoad = SDL_LoadBMP(file.c_str()); if (toLoad) { surfaces[id] = SDL_DisplayFormat(toLoad); SDL_FreeSurface(toLoad); } else { std::cout << "Error loading image \"" << file << "\" (" << id << ")" << std::endl; } } template<> void Resources::load<Mix_Chunk*>(std::string file, std::string id) { sounds[id] = Mix_LoadWAV(file.c_str()); if (!sounds[id]) { std::cout << "Error loading sound \"" << file << "\" (" << id << ")" << std::endl; } } template<> void Resources::unload<SDL_Surface*>(std::string id) { SDL_FreeSurface(surfaces[id]); surfaces.erase(id); } template<> void Resources::unload<Mix_Chunk*>(std::string id) { Mix_FreeChunk(sounds[id]); sounds.erase(id); } template<> SDL_Surface* Resources::get<SDL_Surface*>(std::string id) { std::map<std::string, SDL_Surface*>::iterator iter = surfaces.find(id); return (iter == surfaces.end()) ? NULL : iter->second; } template<> Mix_Chunk* Resources::get<Mix_Chunk*>(std::string id) { std::map<std::string, Mix_Chunk*>::iterator iter = sounds.find(id); return (iter == sounds.end()) ? NULL : iter->second; } #endif // RESOURCES_H_INCLUDED -------------- Build: Debug in Tetris --------------- Compiling: game.cpp In file included from /home/rob/Development/C++/Tetris/game.hpp:13, from /home/rob/Development/C++/Tetris/game.cpp:2: /home/rob/Development/C++/Tetris/resources.hpp:29: error: explicit specialization in non-namespace scope ‘class Resources’ /home/rob/Development/C++/Tetris/resources.hpp:30: error: explicit specialization in non-namespace scope ‘class Resources’ /home/rob/Development/C++/Tetris/resources.hpp:31: error: explicit specialization in non-namespace scope ‘class Resources’ /home/rob/Development/C++/Tetris/resources.hpp:33: error: explicit specialization in non-namespace scope ‘class Resources’ /home/rob/Development/C++/Tetris/resources.hpp:34: error: explicit specialization in non-namespace scope ‘class Resources’ /home/rob/Development/C++/Tetris/resources.hpp:35: error: explicit specialization in non-namespace scope ‘class Resources’ Process terminated with status 1 (0 minutes, 0 seconds) 6 errors, 0 warnings Doesn't seem to be the case with gnu gcc.
  11. It's all pretty much in the title there. I created a class with a few template methods, and I get a load of multiple definition errors from the linker. #ifndef RESOURCES_H_INCLUDED #define RESOURCES_H_INCLUDED #include <map> #include <string> #include <SDL/SDL.h> #include <SDL/SDL_mixer.h> #include <iostream> /** * The Resources class holds some specialized types of resources, allowing for * easy maintaining. */ class Resources { private: std::map<std::string, SDL_Surface*> surfaces; std::map<std::string, Mix_Chunk*> sounds; public: template<class T> void load(std::string, std::string); template<class T> void unload(std::string); template<class T> T get(std::string); }; template<> void Resources::load<SDL_Surface*>(std::string file, std::string id) { SDL_Surface* toLoad = SDL_LoadBMP(file.c_str()); if (toLoad) { surfaces[id] = SDL_DisplayFormat(toLoad); SDL_FreeSurface(toLoad); } else { std::cout << "Error loading image \"" << file << "\" (" << id << ")" << std::endl; } } template<> void Resources::load<Mix_Chunk*>(std::string file, std::string id) { sounds[id] = Mix_LoadWAV(file.c_str()); if (!sounds[id]) { std::cout << "Error loading sound \"" << file << "\" (" << id << ")" << std::endl; } } template<> void Resources::unload<SDL_Surface*>(std::string id) { SDL_FreeSurface(surfaces[id]); surfaces.erase(id); } template<> void Resources::unload<Mix_Chunk*>(std::string id) { Mix_FreeChunk(sounds[id]); sounds.erase(id); } template<> SDL_Surface* Resources::get<SDL_Surface*>(std::string id) { std::map<std::string, SDL_Surface*>::iterator iter = surfaces.find(id); return (iter == surfaces.end()) ? NULL : iter->second; } template<> Mix_Chunk* Resources::get<Mix_Chunk*>(std::string id) { std::map<std::string, Mix_Chunk*>::iterator iter = sounds.find(id); return (iter == sounds.end()) ? NULL : iter->second; } #endif // RESOURCES_H_INCLUDED obj/Debug/main.o: In function `SDL_Surface* Resources::get<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /usr/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../../include/c++/4.3.3/new:105: multiple definition of `SDL_Surface* Resources::get<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:68: first defined here obj/Debug/main.o: In function `Mix_Chunk* Resources::get<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/resources.hpp:74: multiple definition of `Mix_Chunk* Resources::get<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:74: first defined here obj/Debug/main.o: In function `void Resources::unload<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/resources.hpp:61: multiple definition of `void Resources::unload<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:61: first defined here obj/Debug/main.o: In function `void Resources::unload<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/resources.hpp:55: multiple definition of `void Resources::unload<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:55: first defined here obj/Debug/main.o: In function `void Resources::load<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/resources.hpp:45: multiple definition of `void Resources::load<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:45: first defined here obj/Debug/main.o: In function `void Resources::load<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/resources.hpp:33: multiple definition of `void Resources::load<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:33: first defined here obj/Debug/states/mainmenu.o: In function `SDL_Surface* Resources::get<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/states/../resources.hpp:68: multiple definition of `SDL_Surface* Resources::get<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:68: first defined here obj/Debug/states/mainmenu.o: In function `Mix_Chunk* Resources::get<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/states/../resources.hpp:74: multiple definition of `Mix_Chunk* Resources::get<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:74: first defined here obj/Debug/states/mainmenu.o: In function `void Resources::unload<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/states/../resources.hpp:61: multiple definition of `void Resources::unload<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:61: first defined here obj/Debug/states/mainmenu.o: In function `void Resources::unload<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/states/../resources.hpp:55: multiple definition of `void Resources::unload<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:55: first defined here obj/Debug/states/mainmenu.o: In function `void Resources::load<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/states/../resources.hpp:45: multiple definition of `void Resources::load<Mix_Chunk*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:45: first defined here obj/Debug/states/mainmenu.o: In function `void Resources::load<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/rob/Development/C++/Tetris/states/../resources.hpp:33: multiple definition of `void Resources::load<SDL_Surface*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' obj/Debug/game.o:/home/rob/Development/C++/Tetris/resources.hpp:33: first defined here collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 1 seconds) 24 errors, 0 warnings Thanks for any help.
  12. std::map error -- I don't get it...

    Yes, I was still able to turn that beast of an error into something smaller myself, I didn't lose that ability yet. Thanks still for taking your time to explain it again so well, I bet someone else will also find help from this. Now I recall that "discards qualifiers" alwyas has something to do with const-ness, so in the end, I would have been able to solve this myself, had I remembered what the error message is about. I got the idea of using std::map::count() from here, but obviously, your solution that is using purely std::map::find() is more sophisticated. Thanks for all your quick replies, this is in fact the best place for a beginner in programming to come to. edit Howeever, your solution seems to cast an error again. I managed to solve it though. The correct code is now int Options::get(const std::string& toGet) const { std::map<std::string, int>::const_iterator it = values.find(toGet); return (it == values.end()) ? -1 : it->second; }
  13. error: passing ‘const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >’ as ‘this’ argument of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = int, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >]’ discards qualifiers #ifndef OPTIONS_H_INCLUDED #define OPTIONS_H_INCLUDED #include <string> #include <map> class Options { private: std::map<std::string, int> values; public: Options(int, char**); int get(const std::string&) const; void set(const std::string&, int); }; #endif // OPTIONS_H_INCLUDED int Options::get(const std::string& toGet) const { if (values.count(toGet) < 1) { return -1; } return values [toGet]; } The error is addressing the final return statement. From what I understand it doesn't like the fact that I use Options::values as 'this' for std::map::operator[], but I don't really understand what is bothering it, or how to solve it. Can someone please give me a hand? Thanks :) I've gotten too used to the easy peasy java way since my university course... Time to get back to c++
  14. Hey all I searched the forums for some information on good OpenGL books, but I wasn't able to find information that could help me. I thought I'd tell you a bit what I'm looking for, so maybe someone can give me good advice. The book should be platform independant, or at least not focused on Windows. I use Linux mainly. I realise Windows gaming is a lot more widespread that Linux gaming. However, I'm not so much doing this to make a fun game, but more to program something and enjoy the tinkering. I'm coming from programming 2D apps with SDL, I'm not necessarily jumping to OpenGL for its 3D abilities. Creating 3D art sounds very unappealing to me, I'd much rather create more advanced 2D graphical thingamagics (I'm thinking of things like lighting, rotation, etc). So it would be optimal if the book would not focus on 3D development as much as just teaching the use of OpenGL functions. Obviously that teaching can be through 3D demo's, but the focus should be on learning OpenGL, not on 3D programming. A question that came to my mind is whether I should wait for OpenGL 3? I'm not sure how big of an impact the new version will have on books, will they instantly be outdated, or will they miss a lot of information I'd want? I'm assuming I should be fine, but I want to be sure. .
  15. GTK / Glade tool

    Hey all I'm currently designing a tool using Glade. My goal is to make this tool functional using Python and PyGTK somehow. However, I really don't know Python, whereas I'm pretty comfortable in C++. For now, I'd like to make the tool functional using C++, and then maybe convert it to Python some other time. Is this even possible? If so, could someone please point me to the right direction? What I'm mianly looking for is mapping actions to GtkButtons, changing file-locations of GtkImages and setting items in GtkComboBoxes. Thanks
  • Advertisement