Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Kain5056

Member Since 22 Dec 2012
Offline Last Active Today, 07:54 AM
-----

Posts I've Made

In Topic: SDL_Surface to OpenGL texture problem.

Yesterday, 11:36 AM

I have actually been following THIS Tutorial, It says it does it this way for everything to move at the same speed no matter how fast or slow the computer is.

 

I might have missed something though. I will try out your code to see what happens, and I will look into variable and fixed time steps (THIS article seems promising on that subject, but I'll look into it some more).

 

Parallel to that I have already started learnig the basics of SFML, just to be sure. smile.png


In Topic: SDL_Surface to OpenGL texture problem.

Yesterday, 01:03 AM

Well, I tested the game at my friends i7 PC and the experience was pretty much the same (except a small issue with the camera movement, but I think I can fix that one), and the counter was at 580 FPS. Still could not record it on video, though, even though it was a lot less choppy there.

 

This is my FPS counter, taken straight from HERE:

 

void timer::loop()
{
    if( ticks + 1000 < SDL_GetTicks() )
    {
        ticks = SDL_GetTicks();
        frame_count = frame;
        frame = 0;
    }

    speed = ( ( SDL_GetTicks() - last_tick ) / 1000.0f ) * 32.0f;
    last_tick = SDL_GetTicks();
    frame++;
}

int timer::get_FPS() { return frame_count; }

 

I use SDL_Flip at the end of every main loop. I just don't know how to properly use SDL_GL_SwapBuffers().

 

I will take another look into my logic. If I can't get the game to work as I want, I think I may just start learning SFML and start over.


In Topic: SDL_Surface to OpenGL texture problem.

23 May 2013 - 05:57 AM

Choppy when I'm recording, choppier at playback. The controls also become kind of unresponsive when recording, and sometimes the collision detection does not work well. The framerate counter I implemented at the game shows ~110 frames per second when I'm recording.

 

Everything works perfectly when I'm not recording.

 

I know it could be many things, but the first thing that came to my mind is that because SDL uses software acceleration, and the recording software takes a lot out of the system, if I use the graphics card for the game, I would be able to record. I can record any other game I try with no problems.


In Topic: SDL_Surface to OpenGL texture problem.

23 May 2013 - 04:17 AM

Thanks for the advice. smile.png

 

I know it is bad practice to do things I do not understand. My game is actually running good, at 190 frames per second at my old Dual-Core PC, but I'm experiencing problems when I try to record a video of it, even with the lightest program I could find, even though I can record games like Minecraft easily. The framerate does not drop, but the movement is extremely choppy, so I thought that a bit of hardware acceleration might help.

 

After I finish this game I will go ahead and learn OpenGL, but for the time being I just want my SDL game to be able to record on video. unsure.png


In Topic: SDL_Surface to OpenGL texture problem.

23 May 2013 - 04:01 AM

Thanks so much for the help. smile.png

I think I will need some more, though. unsure.png

 

I tried this...:

 

SDL_Surface * load( std::string file )
{
    SDL_Surface * loaded = NULL;
    loaded = IMG_Load( file.c_str() );

    return loaded;
}

void texture( SDL_Surface * get )
{
    glGenTextures(1, &textureID);
    glBindTexture(GL_TEXTURE_2D, textureID);

    int Mode = GL_RGBA;

    glTexImage2D(GL_TEXTURE_2D, 0, Mode, get->w, get->h, 0, Mode, GL_UNSIGNED_BYTE, get->pixels);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    SDL_FreeSurface( get );
}

void apply_surface( int x , int y , SDL_Surface * get , SDL_Surface * give = NULL , SDL_Rect * clips = NULL )
{
    if( get ) texture( get );

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glBindTexture(GL_TEXTURE_2D, textureID);

    glBegin(GL_QUADS);

        glTexCoord2f(0, 0);
        glVertex2f(x, y);

        glTexCoord2f(1, 0);
        glVertex2f(x+get->w, y);

        glTexCoord2f(1, 1);
        glVertex2f(x+get->w, y+get->h);

        glTexCoord2f(0, 1);
        glVertex2f(x, y+get->h);
    glEnd();

    SDL_GL_SwapBuffers();
}

void apply_surface( int x , int y , SDL_Surface * get , SDL_Surface * give , int clips_x , int clips_y , int w , int h )
{
    if( get ) texture( get );

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glBindTexture(GL_TEXTURE_2D, textureID);

    int cx = clips_x / get->w;
    int cy = clips_y / get->h;
    int cw = clips_x+w / get->w;
    int ch = clips_y+h / get->h;

    glBegin(GL_QUADS);

        glTexCoord2f(cx, cy);
        glVertex2f(x, y);

        glTexCoord2f(cx+cw, cy);
        glVertex2f(x+get->w, y);

        glTexCoord2f(cx+cw, cy+ch);
        glVertex2f(x+get->w, y+get->h);

        glTexCoord2f(cx, cy+ch);
        glVertex2f(x, y+get->h);
    glEnd();

    SDL_GL_SwapBuffers();
}

void clean_up()
{
    if(textureID > 0)
    {
        glDeleteTextures(1, &textureID);
        textureID = 0;
    }
    glDisable(GL_TEXTURE_2D);
}

 

 

...But it returns 3, trying to access the wrong piece of memory I think. wacko.png


PARTNERS