Piotr Podsiad?y

  • Content count

  • Joined

  • Last visited

Community Reputation

338 Neutral

About Piotr Podsiad?y

  • Rank
  1. Recently I've been experimenting with component-based game objects. I came to conclusion that the best (for me) approach is to have a GameObject class which is just a container for class derived from IGOComponent. Creation and usage of a game object looks like this: GameObject* go=world->createObject("Object's unique name"); go->addComponent(world->createComponent("Transform")); // position+rotation, written by the physics component, read, by the graphics component go->addComponent(world->createComponent("Graphics")); go->addComponent(world->createComponent("Physics")); go->addComponent(world->createComponent("NPC AI")); go->addComponent(world->createComponent("Health")); go->initialise(); //... IGOComponent* GameWorld::createComponent(const std::string& type) { IGOComponentMgr* manager=m_managers[type]; return manager->createComponent(type); // one manager could handle several types, e.g. "NPC AI" and "Alien AI" would belong the the same manager } //... void GameObject::initialise() { for(IGOComponent* goc : m_components) goc->initialise(this); // setup "connections" between components in one game object } //... void PhysicsComponent::initialise(GameObject* go) { m_owner=go; m_transformGOC=go->component("Transform"); // components can communicate directly } //.. void PhysicsComponent::update() { for(PhysicsComponent* comp : this->colliders()) { GameObject* otherGO=comp->owner(); if(otherGO->hasComponent("Bullet")) { BulletComponent* bt=(BulletComponent*)otherGO->component("Bullet"); DamageMessage* msg=new DamageMessage(); msg->causedBy=otherGO; msg->damage=bt->calcDamage(); m_owner->sendMessage(msg); // components can communicate also "indirectly", using messages. All components of "go" receive msg and can react to it. } } } This design was inspired by an article in Game Programming Gems, part 6.
  2. A Super Mario Source Code

    Unfortunately, I wasn't able to play it on Linux. It seems like the game divides something by zero. I'm posting output from the debugger, hope it helps.  
  3. Multiple windows, always keeping one ontop

    It seems that you can use sf::WindowListener to listen for LostFocus event and when this event is received, you can call sf::Window::SetActive.
  4. Game state communication.

    I would divide states into two categories: application states and game states. Application states would have access only to the “core” subsystems, like window subsystem, sound subsystem, etc. Game would be one of these application states, however this state would also have its “substates” - game states. Game states would be initialised with a pointer to a Game/GameWorld/GameLevel/etc. Object.   That's one option. You could also use the Model-View-Controller pattern. When you look at a map you're just changing the way the world is shown to the user. Model would be the shared game data and game logic. View would be responsible only for rendering correct stuff on the screen. Controller would be responsible for reading input and deciding which View to activate.
  5. Qt in Maya

    If you are using the Q_OBJECT macro (needed for defining new signals and slots), then you have to use MOC. I don't have much experiance with Qt, but this error seems to be like it's caused by missing MOC-generated code. The idea behind the MOC system is simple: it parses input files and generates some additional code, like information about classes (MOC is kind of compile time introspection system), or code of signal methods (you don't implement them yourself, it's done be MOC).
  6. C++ 11 thread not working on CodeBlocks

    I've encountered the same problem, and decided to implement the basic features of std::thread/std::mutex. You can use it yourself, the link is below. This small library has also features, i.e. read-write mutexes and semaphores implemented on Windows and POSIX. It isn't something complicated nor difficult to implement yourself, but saves some time. http://ubuntuone.com/6rLDt59Gl8GWc6wgZsG3Nh
  7. Android GLES1 2d collisions detection

    In case of objects which costst of small number of vertices (like a few squares or something like this) it should have reasonable performance. In fact, I've seen libraries like GWEN, or Allegro5, which transform vertices on CPU, but they also do batching (grouping of multiple objects into one draw call). If you are using textured quads, you would need to implement texture atlases to really benefit from batching.
  8. Android GLES1 2d collisions detection

    So firstly, collision detection should have nothing to do with rendering. Answer to your question is the Separating Axis Theorem (SAT). You can find good explanations on the internet, so I won't describe it. As I said, you shouldn't "mix" physics with graphics. You should rather have two separate objects which handle rendering and simulation. Each of them should have a matrix (may be 3x3 matrix) and the vertices should be transformed separatly. In psedo-code it might look like this: class GameObject { public: GraphicsComponent graphics; PhysicsComponent physics; void update() { physics.update(); // check for collisions graphics.matrix=physics.matrix; // copy transformation of the physical // representation to graphical representation graphics.draw(); } };
  9. How to make 2D sprites and animations?

    You can also try skeletal animation. Skeletal animations can be edited with, for example, Spine (http://esotericsoftware.com/), or  Blender (if you need a free solution). Spine has an open source importer for C++/SFML for their JSON-based format. Animations created with both Spine and Blender can be exported to png files and may be used the same way as traditional sprites.   Edit: I've just found this: http://brashmonkey.com/spriter.htm
  10. c++11 and VS2010 options

    Do you use MS-specific extensions? If no, you may try MinGW, which has pretty good support for C++11, along with, e.g., Qt Creator, or Eclipse.
  11. OpenGL Can't draw a triangle? No error either.

    Shader compilation and mesh drawing could look like this: struct Shader { GLuint vertSh, fragSh; GLuint program; }; Shader CompileShader(const char* vertShCode, const char* fragShCode) { Shader sh; // create and compile vertex shader sh.vertSh=glCreateShader(GL_VERTEX_SHADER); glShaderSource(sh.vertSh, 1, &vertShCode, NULL); glCompileShader(sh.vertSh); // create and compile fragment shader fh.fragSh=glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(sh.fragSh, 1, &fragShCode, NULL); glCompileShader(sh.fragSh); // create, bind attribute locations and link program sh.program=glCreateProgram(); glAttachShader(sh.program, sh.vertSh); glAttachShader(sh.program, sh.fragSh); /* * Arguments are: program's handle, an index which will be used * as an argument for glVertexAttribPointer and glEnableVertexAttribArray, * and a name which identifies the attribute in the vertex shader. */ glBindAttribLocation(sh.program, 0, "inPosition"); glBindAttribLocation(sh.program, 1, "inColour"); // other attributes; they must be bound before calling glLinkProgram glLinkProgram(sh.program); return sh; } void DrawMesh(const Shader& sh, GLuint vbo, GLuint numVertices) { glUseProgram(sh.program); glBindBuffer(GL_ARRAY_BUFFER); glEnableVertexAttribArray(0); // index, 0 == "inPosition" glVertexAttribPointer( 0, // index, 0 == "inPosition" 3, // size false, // normalised 24, // vertex' stride, 3*float for position, and 3*float for colour 0 // offset in the vbo ); glEnableVertexAttribArray(1); // vertex colour glVertexAttribPointer(1, 3, false, 24, (void*)12); glDrawArrays(GL_TRIANGLES, 0, numVertices); } I've omitted checking for errors to simplify the code.   Simple vertex shader: #version 120 // "attribute" instead of "in" attribute vec3 inPosition; attribute vec3 inColour; // "varying" instead of "out" varying vec3 colour; void main() { gl_Position=vec4(inPosition, 1); colour=inColour; }   Simple fragment shader: #version 120 // "varying" instead of "in" varying vec3 colour; void main() { gl_FragData[0]=colour; }     glEnableClientState and glVertexPointer is for fixed function pipline, where vertex attributes were "hard coded" in OpenGL (though you can use them in old GLSL). glEnableVertexAttribArray, glVertexAttribPointer, and glBindAttribLocation are for modern OpenGL. By using them ( you can specify custom name for each attribute.   The first method was abandoned in new versions of OpenGL, so I suggest using the second one (it is in OpenGL 2.0 core).   Aparently it depends on a specific driver. AFAIK this isn't bound to work. Just a hack to avoid thowing shaders at you from the beginnning.   If it teaches shaders, then it teaches programmable pipeline.
  12. OpenGL Can't draw a triangle? No error either.

    You're right, in/out variables are available since GLSL 1.40. In the previous version you have to use "attribute" keyword (for vertex shader's input), "varying" keyword (for variables passed from a vertex shader to a fragment shader) and "gl_FragData[]" for fragment shader's output.   "layout" is avialable since even newer version (I don'r remember which exactly). You have to specify indices from C++ using glBindAttribLocation.
  13. OpenGL Can't draw a triangle? No error either.

    1) Refering to post http://www.gamedev.net/topic/638573-opengl-cant-draw-a-triangle-no-error-either/?view=findpost&p=5030781: you aren't using shaders, so you need to use old-style vertex specification functions: glEnableClientState and glVertexPointer: static const GLfloat vertexBufferData[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f }; GLuint vertexBuffer; glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBufferData), vertexBufferData, GL_STATIC_DRAW); // glEnableVertexAttribArray(0); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); // glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0); glVertexPointer(3, GL_FLOAT, 12, 0); glfwEnable(GLFW_STICKY_KEYS); while (glfwGetWindowParam(GLFW_OPENED)) { if (glfwGetKey(GLFW_KEY_ESC)) { break; } glClearColor(0.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); 2) To your last post: Mesa doesn't support GLSL 4.20 which you're using. Try GLSL 1.20 (or 1.30, but I'm not sure if it is implemented in your version Mesa).
  14. dll error, I think

    Try checking your application with Dependency Walker, it shows which DLLs are missing.
  15. which IDE should i use for opengl?

    The best free IDE I've ever used is Eclipse. It has many useful features like better code completion, syntax highlighting, Task List, hundreds of free plugins for connecting with version control systems, etc., profiler integration, even a built-in web browser ;) not available in Visual Studio Express Edition. The only reason for which I would use VS EE is MS's compiler - although Eclipse has integration with it, it isn't able to debug programs built with MS's compiler.