• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

154 Neutral

About bluehailex

  • Rank
  1. I've been trying to create a simple height map terrain renderer using tessellation shaders in OpenGL. Everything works fine, except for computing a global texture coordinate for sampling the height map. The rendering starts with a call to glDrawArraysInstanced(GL_PATCHES, 0, 4, terrainSize*terrainSize). In the vertex shader, the world position is computed from gl_InstanceID. So far, I'm then calculating a global texture coordinate by taking worldPos / terrainSize. In this coordinate system, [0,0] and [1,1] should be in opposite corners of the height field.   As you can see in the attached images, the coordinates on the edges are messed up and wrap around to the other side. You can see red bleeding into green, and green bleeding into red. By setting the wrap mode to ClampToEdge, the problem is "hidden". In the pictures, I'm drawing a 25 patches (5x5). I've also tried clamping the  interpolated texture coordinates in the TES with tesOut.tc = vec2(clamp(tc.x, 0.0, 1.0), clamp(tc.y, 0.0, 1.0));, but that doesn't help either.     Vertex shader #version 430 core out VSOut { vec2 tc; } vsOut; uniform int terrainSize; void main() { const float M = 1.0; const vec4 vertices[] = vec4[](vec4(M, 0, 0, 1.0), vec4(M, 0, M, 1.0), vec4(0, 0, 0, 1.0), vec4(0, 0, M, 1.0)); vec4 worldPos; worldPos.x = float(gl_InstanceID % terrainSize) + vertices[gl_VertexID].x; worldPos.y = 0.0; worldPos.z = float(gl_InstanceID / terrainSize) + vertices[gl_VertexID].z; worldPos.w = 1.0f; vsOut.tc.x = worldPos.x / terrainSize; vsOut.tc.y = worldPos.z / terrainSize; gl_Position = worldPos; } Tessellation control shader #version 430 core layout (vertices = 4) out; in VSOut { vec2 tc; } tcsIn[]; out TCSOut { vec2 tc; } tcsOut[]; void main() { if (gl_InvocationID == 0) { const float inner = 1.0; const float outter = 1.0; gl_TessLevelInner[0] = inner; gl_TessLevelInner[1] = inner; gl_TessLevelOuter[0] = outter; gl_TessLevelOuter[1] = outter; gl_TessLevelOuter[2] = outter; gl_TessLevelOuter[3] = outter; } gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; tcsOut[gl_InvocationID].tc = tcsIn[gl_InvocationID].tc; } Tessellation evaluation shader #version 430 core layout (quads) in; in TCSOut { vec2 tc; } tesIn[]; out TESOut { vec2 tc; } tesOut; uniform mat4 modelViewMatrix; uniform mat4 perspectiveMatrix; void main() { vec2 tc1 = mix(tesIn[0].tc, tesIn[1].tc, gl_TessCoord.x); vec2 tc2 = mix(tesIn[2].tc, tesIn[3].tc, gl_TessCoord.x); vec2 tc = mix(tc2, tc1, gl_TessCoord.y);     vec4 p1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);     vec4 p2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, gl_TessCoord.x);     gl_Position = perspectiveMatrix * modelViewMatrix * mix(p2, p1, gl_TessCoord.y); tesOut.tc = tc; } Fragment shader #version 430 core layout (binding = 0) uniform sampler2D sampler; out vec4 color; in TESOut { vec2 tc; } fsIn; void main() { color = texture(sampler, fsIn.tc); }
  2. Problem with SDL (Undefined Reference)

    Glad I could help. SFML is probably going to be easier for you to learn, but once you built a simple framework around SDL or SFML it wont matter.
  3. Problem with SDL (Undefined Reference)

    Either something didn't build quite right, or CodeBlocks cannot find your output executable. Try running your program from the explorer. As for SDL in general, it is a great library. Very portable, but it doesn't come with the greatest performance out of the box. It uses software rendering, as opposed to hardware rendering (using the GPU). If you are planning on doing your own rendering in OpenGL, it will work out very well. However, there is a similar library called SFML. It uses hardware rendering by default, and will give you great performance compared to SDL. I haven't used SDL in a while, so things may have changed. SFML was written in C++ and is object oriented, while SDL was written in C and is not object oriented. SDL and SFML both support Windows/Linux/Mac/FreeBSD, but SDL goes even further to support consoles and even some mobile operating systems. SFML is pretty active, so I would not be surprised if it gets ported to consoles/mobile devices as well.
  4. tictactoe game switching turns problem :( help pleas

    I think you need to switch the turns when the mouse button is released, not down. The problem is your loop is updating so many times while the mouse button is down that it switches the turn 100+ times before the user lets the button up.
  5. Problem with SDL (Undefined Reference)

    Try linking directly with the libraries by supplying the absolute path to them instead of giving the linker options. For example: "C:\Dev\Lib\SDL\SDL_image.lib" Make sure you put the paths in the "Link Libraries" section, not "Other linker options".
  6. Problem with SDL (Undefined Reference)

    It is possible you are linking with the wrong SDL_image library. You might be using an x64 build, when you really are x86. Or you may have even downloaded the wrong SDL_image zip all together from [url="http://www.libsdl.org/projects/SDL_image/"]here[/url]. I don't think there is anything wrong with your code.
  7. Problem with SDL (Undefined Reference)

    Try putting -lSDL_image at the top. The problem is you are trying to use IMG_Load(), which is defined in SDL_Image. The linker can be a bit stupid with Code::Blocks, so you might have to rearrange the options. Also, I don't see a need for SDL_image.lib to be in you output directory.
  8. [quote name='edd²' timestamp='1326744258' post='4903343'] This line looks scary: [color=#666600]*[/color][color=#000000]actor[/color][color=#666600].[/color][color=#000088]get[/color][color=#666600]()[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#666600]*([/color][color=#660066]Actor[/color][color=#666600]*)[/color][color=#000000]entity[/color][color=#666600].[/color][color=#000088]get[/color][color=#666600]();[/color] If you're going down the route of performing dynamic casts, you'd need one here too, presumably? Can you strip down the code in order to provide a small single-source-file example that illustrates the problem? [/quote] Well, I discovered that I was actually putting the player in a shared_ptr elsewhere in my code, so instead of declaring a Player* player = new Player(); I was doing shared_ptr<player>; Anyways, it works now, but about the [color=#666600]*[/color][color=#000000]actor[/color][color=#666600].[/color][color=#000088]get[/color][color=#666600]()[/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] [/color][color=#666600]*([/color][color=#660066]Actor[/color][color=#666600]*)[/color][color=#000000]entity[/color][color=#666600].[/color][color=#000088]get[/color][color=#666600]() [/color]I am only trying to copy the data pointed by the shared pointer for the template entity. Should I implement some copy method instead? I just want the actor to have all of the data contained in the entity. However, the entity shared_ptr<> may actually have some actor specific data, so that is why I cast it to an actor. Maybe this is a better alternative? [CODE]*actor.get() = *std::dynamic_pointer_cast<actor>(entity).get();[/CODE]
  9. So I have a manager that stores entities with a std::vector< std::shared_ptr<Entity> >. Here is a relevant outline of the manager: [CODE] #define SharedPtr std::tr1::shared_ptr class EntityManager { private: std::vector<SharedPtr<Entity> > mEntities; std::vector<SharedPtr<Entity> > mTemplateEntities; public: CreateEntity(std::string templateName, hx::Vector2D pos, std::string handle); SharedPtr<Entity> GetEntity(int id); SharedPtr<Entity> GetEntity(std::string handle); SharedPtr<Entity> GetTemplateEntity(std::string name); };[/CODE] Entity is an abstract base class, with a derived class Actor. I add entities to the manager by doing the following: [CODE] void EntityManager::CreateEntity(std::string templateName, hx::Vector2D pos, std::string handle) { SharedPtr<Entity> entity( mWorld->GetEntityManager()->GetTemplateEntity(templateName) ); entity->SetPos(pos); entity->SetHandle(handle); if (entity->GetType() == ACTOR) { SharedPtr<Actor> actor( new Actor() ); *actor.get() = *(Actor*)entity.get(); mWorld->GetEntityManager()->AddEntity( actor ); } } [/CODE] To access an entity in the manager, I call EntityManager::GetEntity(62). If the entity accessed needs to be used as an Actor (derived type), I will use this: [CODE] std::dynamic_pointer_cast<Actor>(manager->GetEntity(2)) [/CODE] However, I am facing a problem with implementing a player system. This is an outline of the player class: [CODE] class Player { private: SharedPtr<Actor> mTarget; public: bool Player::Init(std::string handle, EntityManager* manager) { //the following is just a test, and it works SharedPtr<Actor> test(std::dynamic_pointer_cast<Actor>(manager->GetEntity(handle))); //this next line (what I actually want to do), gives an unhandled exception) mTarget = std::dynamic_pointer_cast<Actor>(manager->GetEntity(handle)); //I have also tried to do the following, but it still crashes mTarget = test; return mTarget; } }; [/CODE] When I run it in the Visual C++ 2010 debugger, I get an unhandled exception, in the middle of the swap() method in the utility standard header (line 103) whenever I try to assign a SharedPtr<Actor> to mTarget. Is there a more correct way to cast from the base class Entity to the derived class Actor? Do I need to initialize mTarget somehow?
  10. I'm new

    [color=#1C2837][size=2][quote]should I continue using codeblocks or should I switch to visual studio or possibly something else? [/quote][/size][/color] [color=#1C2837][size=2] [/size][/color] [color="#1c2837"][size="2"]Visual Studio's debugger is quite a bit nicer in my opinion. It may make debugging less of a headache.[/size][/color]
  11. [quote name='ILoveJesus' timestamp='1322529361' post='4888643'] This is where my problem lies. I want my sprites to have two separate positions, 1 the position relative to the screen which always changes and 2 the level position which is always static, unless the sprite moves of course. [/quote] You really want to avoid having your sprite positions be relative to the camera. The screen (or camera) should be looking at the world from it's own perspective, and the sprites should not depend on the camera's position. You can give the camera it's own world position, and have it determine where it should be looking in the world. [quote name='ILoveJesus' timestamp='1322529361' post='4888643'] Taking a sprite in my level editor and placing it is simple when talking about screen position, but determining where in the level I place it is what I need to determine. How could I go about doing this?I am coding in c++ btw with Directx11. [/quote] If the camera has a world position (assuming it represents the top left corner of the screen), you can convert screen coordinates to world coordinates by adding the camera's world position to the screen position of the sprite you are placing.
  12. Making a board game with C++ and SDL

    [quote name='Tony Sharp' timestamp='1322511720' post='4888562'] The designs and gameplay for my game are done, and the image elements are saved. I have some experience with C++, but very little experience with SDL. To get things started, I'd like to know how to load my [i]board.png[/i] file into a window as a background. Your help would be greatly appreciated. [/quote] [url="http://lazyfoo.net/SDL_tutorials/lesson01/index2.php"]This[/url] is a pretty good tutorial that will show you how to get an image on the screen, but if you want support for PNG files you will want to follow up with [url="http://lazyfoo.net/SDL_tutorials/lesson03/index.php"]this[/url] tutorial. The [url="http://lazyfoo.net/SDL_tutorials/index.php"]site[/url] also has other tutorials if you want to learn more about SDL.
  13. Problem getting SDL to build in Visual Studio 2010

    One problem is you are using "SDL_EVENT", when it is actually defined as "SDL_Event" in the SDL library.
  14. Choices

    [quote name='artcorbeau' timestamp='1321856539' post='4886113'] Now for the 3d modeling which utility should I use ? (freeware and the easiest to understand if possible) [/quote] Maybe not the easiest, but probably the best 3D modeler out there for free is [url="http://www.blender.org/"]Blender[/url]. There is a pretty large community going for it too.
  15. Choices

    [color=#1C2837][size=2][quote]Python aside, which game making utility would be the best choice to do this kind of game?[/quote][/size][/color] If you are making a 3D game, you might want to look into [url="http://unity3d.com/unity/"]Unity[/url]. For 2D games, there are some on this site, [url="http://www.ambrosine.com/resource.html"]http://www.ambrosine.com/resource.html[/url].
  • Advertisement