Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sponji

Member Since 14 Jan 2011
Offline Last Active Today, 11:11 AM

#5206500 SDL2 and openGL3-4

Posted by Sponji 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 Sponji 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 Sponji 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 Sponji 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 Sponji 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
            final_vertices.push_back(tmp_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 Sponji 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 Sponji on 08 November 2014 - 04:07 PM

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

private:
    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 Sponji 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.




#5172468 Bullet physics wireframe drawn in a wrong place

Posted by Sponji on 09 August 2014 - 09:30 AM

Do you set the projection and view matrices somewhere?

 

Maybe something like this:

void World::Draw() {
	// ... 

	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(glm::value_ptr(projection_matrix));

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(glm::value_ptr(view_matrix));

	m_dynamicsWorld->debugDrawWorld();
}



#5169985 Segmentation fault when loading texture using SOIL

Posted by Sponji on 29 July 2014 - 03:10 AM

And you're actually defining GL_GLEXT_PROTOTYPES so that the glGetStringi gets declared? I just made a simple test, and compiling it as C++ creates an error.

 

gcc -Wall -g test.c $(pkg-config --libs --cflags sdl2) -lSOIL -lGL -lGLEW && ./a.out:

test.c:10:3: warning: implicit declaration of function ‘glGetStringi’ [-Wimplicit-function-declaration]

g++ -Wall -g test.cpp $(pkg-config --libs --cflags sdl2) -lSOIL -lGL -lGLEW && ./a.out:

test.cpp:10:53: error: ‘glGetStringi’ was not declared in this scope



#5165270 VBO and glIsBuffer

Posted by Sponji on 07 July 2014 - 09:08 AM

Sounds like there's no opengl context active when you try to call those opengl functions?




#5165034 Transparency Issue

Posted by Sponji on 06 July 2014 - 06:54 AM

The problem is basically that the triangles are not still sorted. For example, if you want one object which has two transparent boxes in it, how do you know which box of those will be drawn first? It will look weird depending on the viewing direction.




#5165021 Transparency Issue

Posted by Sponji on 06 July 2014 - 05:52 AM

You probably have depth writing enabled (glDepthMask), so when you draw the transparent quad first, it will write the depth for those transparent pixels. And now when you try to draw the other object behind it, it will skip the drawing the pixels because of depth testing (something is in front of the pixel). Simplest way to solve this is to render opaque objects first, then transparent objects from back to front. It still won't work for all kinds of shapes though.

 

Try changing the order you render, first the textured box and then the transparent thing.




#5162835 My Kingdom for a Link to a Past Post

Posted by Sponji on 25 June 2014 - 02:07 PM

Maybe this one, http://www.gamedev.net/topic/630721-mind-if-we-discuss-vbo-streaming/




#5156333 glFrontFace GL_CW vs. GL_CCW question

Posted by Sponji on 27 May 2014 - 01:44 PM


Now, mystery to me that that my points specified in clockwise order, but I see my square as white.

CCW = counterclockwise

 

Try drawing the vertex positions on a paper, +x is to the right, +y is up, it's white when the order is counter clockwise.






PARTNERS