Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 14 Jan 2011
Offline Last Active Today, 02:17 PM

#5246895 Perspective projection makes triangle disapear

Posted by on 16 August 2015 - 07:33 AM


glm::perspective takes fov as radians nowadays. So you probably want to use glm::radians(60.0f).


I just checked the glm docs.  http://glm.g-truc.net/glm.pdf

It's not radians, its degrees.



Check better, that's probably outdated. See http://glm.g-truc.net/0.9.7/api/a00174.html#gac3613dcb6c6916465ad5b7ad5a786175

#5246852 Perspective projection makes triangle disapear

Posted by on 16 August 2015 - 02:20 AM

glm::perspective takes fov as radians nowadays. So you probably want to use glm::radians(60.0f).

#5218158 Nothing visible when doing indexed drawing

Posted by on 21 March 2015 - 04:36 PM

So, did it work after you changed it to 6?

#5212673 SDL Texture Relations

Posted by on 24 February 2015 - 05:17 AM

1) Yes
2) Not sure if you could compare those like that, because textures don't have position or anything, they are just "images". Maybe you could think them as a brushes?
3) Seems right
4) So, you could generate the images for all object types and then create textures(or maybe one bigger texture) from those. But I would just create a single texture for one small tile and render that with SDL_RenderCopy multiple times to correct places on the screen.

#5210846 Disassociate mouse with its position

Posted by on 15 February 2015 - 09:32 AM

You could also use raw input instead of querying the cursor location. I haven't used that myself, but it should work well: https://msdn.microsoft.com/en-us/library/windows/desktop/ee418864%28v=vs.85%29.aspx.

#5208138 Get started with 'sliding' collision response

Posted by on 02 February 2015 - 12:22 AM

I usually just separate the movement for the axises.

player.x += movement.x;
if(map.collides(player)) { /* move back on x-axis */ }

player.y += movement.y;
if(map.collides(player)) { /* move back on y-axis */ }

#5206586 Trouble loading and displaying with transparency, 8bit indexed bitmaps

Posted by on 25 January 2015 - 12:50 PM

I think this line makes your code slow:

color = bitmap.Palette.Entries[index];

Because this says: "This property returns a copy of the ColorPalette object used by this Image."


Maybe just grab the palette/entries first so you can access them directly?

#5206500 SDL2 and openGL3-4

Posted by on 24 January 2015 - 10:02 PM

SDL2 works just fine, just tell it what kind of context you want to create with a few calls to SDL_GL_SetAttribute. It doesn't handle the function pointers for the needed OpenGL functions though, so use GLEW or something similar for that to make your life easier.

#5205282 Having a lot of trouble getting OpenGL to work

Posted by on 19 January 2015 - 07:28 AM

You should check the return value from glewInit instead of using glGetError. Also, if I remember correctly, there's a bug(?) in glew so that its initialization function uses glGetString or something and it causes a silly error because it's not allowed in the context. You can just ignore that by calling simply glGetError once after glewInit.


Do something like this:

glewExperimental = GL_TRUE;

GLenum error = glewInit();
glGetError(); // ignore the silly error

if(error != GLEW_OK) {
	// glew failed

Edit: That GL_INVALID_ENUM thing is mentioned here: https://www.opengl.org/wiki/OpenGL_Loading_Library#GLEW_.28OpenGL_Extension_Wrangler.29

#5197417 Rendering quad but something is missing

Posted by on 10 December 2014 - 12:19 PM

You're transforming the vertices by modelViewProjectionMatrix, but I don't see code for calculating that matrix. You are probably missing that.

#5197406 Rendering quad but something is missing

Posted by on 10 December 2014 - 11:12 AM

Change the translation for your view matrix to 0,0,-10 and create the positions for the quad like this:

//  x   y   z
// ----------
// -1, -1,  0  bottom left
//  1, -1,  0  bottom right
//  1,  1,  0  top right
// -1,  1,  0  top left
quad[0].position[0] = -1;
quad[0].position[1] = -1;
quad[0].position[2] =  0;
quad[1].position[0] =  1;
quad[1].position[1] = -1;
quad[1].position[2] =  0;
quad[2].position[0] =  1;
quad[2].position[1] =  1;
quad[2].position[2] =  0;
quad[3].position[0] = -1;
quad[3].position[1] =  1;
quad[3].position[2] =  0;

And the reason why you're getting -1 from glGetUniformLocation and glGetAttribLocation is that your shader program doesn't actually use those variables for anything, so they are optimized out. It still "fine" to call glUniformX(-1, ...) though, it shouldn't just do anything.

#5195460 OBJ File Problem

Posted by on 30 November 2014 - 04:14 AM

You can just loop over all indices from the obj and check if a vertex with the position and texture coordinate is already created. If not, then create a new vertex with the attributes and push its index to the list of indices.


Maybe something like this:

std::vector<Vertex> final_vertices;
std::vector<unsigned int> final_indices;

for(const Face &face : faces) {
    for(int i=0; i<3; ++i) {
        position = positions[face.position_index[i]]
        texcoord = texcoords[face.texcoord_index[i]]
        normal = normals[face.normal_index[i]]

        Vertex tmp_vertex(position, texcoord, normal)
        // Check if a vertex with the specified attributes is already generated
        if(tmp_vertex is already in vertices) {
            // Add the index of the already generated vertex
            final_indices.push_back(/*index of tmp_vertex in vertices */);
        } else {
            // Add the new vertex
            // The index of the new vertex is the last one in the vector
            final_indices.push_back(final_vertices.size() - 1);

#5192002 Tilemap array is flipped

Posted by on 10 November 2014 - 02:14 AM

Seems like you're mixing i and j in the Node's constructor? I think it should be also better to flip the loops, first height and then width.


I'd do something like this:

for (unsigned int y = 0; y < height; ++y)
    for (unsigned int x = 0; x < width; ++x)
        map.push_back(new Node(x * 32 , y * 32 ));
        map[y * width + x] = ...;

#5191850 SFML Passing RenderWindow reference to constructor error

Posted by on 08 November 2014 - 04:07 PM

Change the renderWindow to a reference and assign it in the constructor's initialization list.

    sf::RenderWindow &renderWindow; // Make it a reference
// And it must be assigned in the initialization list because it's a reference
MapRender::MapRender(sf::RenderWindow &thatWindow)
: renderWindow(thatWindow)
{ }

#5173051 Mixed functions order in code to render heightmap

Posted by on 12 August 2014 - 04:07 AM

glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(hmIndices), hmIndices, GL_STATIC_DRAW);

The size parameter seems to be wrong, it should probably be sizeof(unsigned int) * 27. I think you should also change the actual type to unsigned int, because you're using it as GL_UNSIGNED_INT.