Jump to content

  • Log In with Google      Sign In   
  • Create Account

I put on my robe and...

Member Since 29 Nov 2011
Offline Last Active Sep 02 2013 12:01 PM

Topics I've Started

SDL 1.2 Engine - vsync issues in ubuntu

30 August 2013 - 04:31 PM

I am making a game using SDL 1.2 for the cross-platform benefits. I use openGL calls for all the rendering.

I have called
 

SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

before setting SDL video mode, and when I call get_attribute after everything is set up, a "1" is returned for success. In addition, if I manually configure the environment variable via an "export" of the vsync variable, then SDL properly says that the environment variable has overridden SDL settings and that Vsync is on.

Everything says that vsync is on and works, but my game still stutters in Linux...
In Windows, the game also stuttered until I added the swap_control and it became smooth as butter.

 

This made me believe that something was wrong fundamentally with my loop, as I read that
"A good game loop will provide the delays necessary to make Vsync unnecessary"
So I offer to you my delay method:
 

if((1000/FPS)>(SDL_GetTicks()-start_time))
{
SDL_Delay((1000/FPS)-(SDL_GetTicks()-start_time)); //Yay stable framerate!
}

I had a different one, but clipped this from the internet thinking maybe that was my problem. It changed nothing.
the start_time is at the beginning of the while loop, and the FPS is set to 50 or 60, tried both.


Below is the code I use to set up my SDL video mode:

SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE);

I have also tried using HW_ACCEL, SWSURFACE, and several other settings.

 

The following is just standard setup for 2d opengl

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, -1.0f, 1.0f);

glMatrixMode( GL_MODELVIEW );
glEnable( GL_TEXTURE_2D );
glLoadIdentity();

glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );

glShadeModel(GL_SMOOTH);

glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );



This is pretty much all the code that goes into setup. Again, it works beautifully in windows now that I have added the vsync, but it behaves the same in Linux (Ubuntu 12.10) regardless of the vSync being set.

Also, I have gone through compiz settings to try enabling vsync, triple buffering, and other opengl options. The enabling and disabling of these options ALL had no effect on my game's small stutter.

-----------------------

I'm going to ask this as an aside, but it isn't the main focus of what I want from this post - so please only contribute to this part of the question if you have substantial knowledge of both versions of SDL and can offer an appropriate opinion for a 2d game (platformer)....
With the recent release of sdl 2, should I upgrade to it? My engine is set up so that I can replace it without too much trouble and I am at the beginning stages of making my game still. I know nothing at all of SDL2, but am decently familiar with 1.2. I wouldn't even use SDL were it not for the fact that I don't want to deal with wrapping OpenGL for cross platform call. I use SDL right now for event handling, image loading of PNGs and converting them to 32bit ints for gl textures, and I will eventually use it for music.


C++ One header to rule them all

29 November 2011 - 11:41 AM

My question involves header files in C++.

I currently have a few different classes and I separate them into a .h and a .cpp (such as regexClass.h and regexClass.cpp)

I have one header called theHeader.h and it includes all of my other headers:


#pragma once   // or I use ifndefs as well here
#include <iostream>
#include <fstream>
#include <string>

#include "regexClass.h"
#include "classificationClass.h"

enum fileType {

    ZIP = 0x4034b50,
    GZIP = 0x88b1f,
    SEVENZIP = 0xafbc7a37,
    BZIP = 0x39685A42,
};



when I build classifcationClass.cpp it requires access to the regexClass.h...... Instead of including regexClass.h, I just include theHeader.h.

#include "theHeader.h"
using namespace std;

classificationClass::classificationClass()
{
      init();
}

classificationClass::init()
{
 	regexClass *theRegex = new regexClass(); //I can create a regexClass without having to "#include "regexClass.h" up at the top, since it is already included in "theHeader.h"
 	
 	if(theRegex.match(ZIP, filePath))
   	cout<<"Victory"<<endl;
}


This grants classificationClass.cpp access to regexClass, <iostream>, <string>, etc. without me having to re-include everything all over again. Since the compiler will only include the files once, this code would work and compile just fine. The other crucial element to this working, is the order of file inclusion. classificationClass uses a regexClass object, thus "regexClass.h" is included in "theHeader.h" before "classificationClass.h" is.

My coworker stresses to me that this is a bad programming practice, and wants to copy my "theHeader.h" includes into each of my separate class .h files. Is it bad practice to do this? Or am I just that awesome?

Thanks :)

PARTNERS