Jump to content

  • Log In with Google      Sign In   
  • Create Account


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

#5309281 Is SDL the right or wrong choice for my engine?

Posted by on 03 September 2016 - 01:55 AM

I've been using SDL for years and I think it's just awesome to get stuff working crossplatform much easier. But of course it still takes time to get some specific things working in some weird situations. Probably took me a few days to get my little framework working with Emscripten the first time I used it, mostly because of a shader bug which only happened on Chromium.


I think you're in the right direction with designing it to work with different libraries, the final game under your framework/engine shouldn't care what library is creating the graphics contexts or processing input events or whatever. You can even make your own code for handling those later on, if it's really needed. Just don't spend too much time on making some random wrapper classes at first. Make it work with one library first and clean up if/when you realize something could be done better.

#5293412 [OGL] Textures are not displaying properly

Posted by on 25 May 2016 - 12:20 PM

And you've made sure the shaders compile fine? Does glGetUniformLocation return valid location? Did you bind the attribute locations correctly? Btw, AMD's CodeXL is the new gDEBugger.

#5293406 [OGL] Textures are not displaying properly

Posted by on 25 May 2016 - 11:47 AM

I don't see anything wrong with the vertex attributes, but yeah, it's usually unnecessary to disable them. You can just set up everything in your VAO and its buffers and attributes will be remembered next time you bind the VAO.


One problem could be with your glUniform call, you're passing weird stuff for it, you shouldn't use texture id for it. Maybe that's not the actual problem if the texture id is a sane number for glActiveTexture call, but at least I'd suggest fixing that one.

GLuint texture_id = ...;
int index = 0;
glActiveTexture(GL_TEXTURE0 + index);
glUniform1i(shader.getUniformLocation("sampler"), index);
glBindTexture(GL_TEXTURE_2D, texture_id);

#5293106 glMultiDrawArrays does not render properly

Posted by on 23 May 2016 - 02:10 PM

And did you try using byte offset for glBufferSubData and index offset for glMultiDrawArrays?

#5291619 Framerate Independent Mouse Movement

Posted by on 14 May 2016 - 03:45 PM

You don't ignore it, it's an event. You get the event and you process the values from it.

void events() {
    SDL_Event event;
    while(SDL_PollEvent(&event)) {
        switch(event.type) {
            case SDL_MOUSEMOTION: {
                // Ooh, the mouse was moved, let's apply the motion.
                GameState->CameraRot += v3(event.motion.yrel, event.motion.xrel, 0.0f);
            } break;

void update() { ... }
void render() { ... }

void mainloop() {
    while(running) {

#5291608 Framerate Independent Mouse Movement

Posted by on 14 May 2016 - 02:25 PM

Yeah, but you're still applying the motion multiple times, and you shouldn't even use delta time for that. If I move my mouse by X amount, I want it to rotate my camera by Y degrees, it doesn't matter how many frames or seconds it took. You can even try it by moving the rotation code directly in the event handling. And you could still add some lerping on top of that code if that's what you're looking for. Like smoothed_rotation = slerp(smoothed_rotation, actual_rotation, delta) or something, and that should happen in the frame update.

#5291147 Most efficient way of looping trough a sprite grid

Posted by on 11 May 2016 - 09:08 AM

So, just a tilemap? If each cell contains a sprite and they are just put in the vector, you can get the index with y * tiles_per_x + x

// Create a sprite for each tile
for(int y=0; y<tiles_per_y; ++y) { // first y
    for(int x=0; x<tiles_per_x; ++x) { // then x
        // ... and the index here for the pushed sprite is y * tiles_per_x + x

// Find the tile coordinates under mouse
int x = mouse_x / tile_width;
int y = mouse_y / tile_height;

// Convert the tile coordinates to index and get the sprite for it
int index = y * tiles_per_x + x;
sprite_under_mouse = sprites[index];

#5289320 linked list of struct that is derived from another c++

Posted by on 29 April 2016 - 02:38 PM

while (p!= NULL) p = p->next;
return p;

Doesn't that just always return null?

#5285537 Difference when enabling index buffer before and after GL_ARRAY_BUFFER

Posted by on 06 April 2016 - 10:41 PM

You should show how EnableVAO, EnableVBO and Update methods are implemented. And what is the code for failing render? Since you grouped VAO and vertex buffer lines together, I guess you just bound the index buffer before binding the VAO. Just remember that the VAO should be bound first, because the buffers are bound to it.


#5283346 Spritebatch only renders first time

Posted by on 25 March 2016 - 02:12 AM

Maybe I wrote in a silly way, but you need to keep the _numAttributes = 0 line in the dispose method too. That's needed for addAttribute method so that it understands to reset counting from zero.


//enable the shader 
void GLSLProgram::use() {

//disable the shader
void GLSLProgram::unuse() {

void GLSLProgram::dispose() {
    if (_programID) glDeleteProgram(_programID);
    _numAttributes = 0;


#5283075 How can I locate a memory leak?

Posted by on 24 March 2016 - 12:07 AM

I started using clang's address sanitizer few months ago, and it seems really awesome compared to slow valgrind. It's even easy to use, just compile and link your program with -fsanitize=address and it will tell you what goes wrong.

#5280006 SDL Renderer Issue

Posted by on 07 March 2016 - 06:44 AM

You've changed the code? The codes you gave don't initialize it.

#5279995 SDL Renderer Issue

Posted by on 07 March 2016 - 05:52 AM

You don't seem to initialize Sprite's renderer anywhere?

#5279883 [C++/D3D11] Problem with texturing a model

Posted by on 06 March 2016 - 04:15 PM

My guess would be that 

ObjectDatas[ArrayCount].texture = m_texture;

should be

ObjectDatas[i].texture = m_texture;

#5246946 Perspective projection makes triangle disapear

Posted by on 16 August 2015 - 12:49 PM

Good catch. I haven't even paid any attention to those example codes because I've been just using the library for years and checked for the release notes. And the release notes say that it was changed in
Stupid internet points though, not sure why I get -6 for bringing that up.