Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmartinis_shaken

Posted 09 November 2013 - 09:17 AM

My game has an issue with micro stuttering. Every second or two the game "jumps" a little, as if a few frames are missed. There is no tearing of the screen, just a small pause and then the jump forward. The issue occurs whether the character is moving or not, scrolling or not (just more noticeable when scrolling), etc. Without fail, every second or two, the game will just jerk/jump/stutter.
 
The issue is similar to this post, though VSync does not fix the problem.
 
----------------------------------------
60 Frames displayed in 1 second 
Logest logic time: 1ms
Logest render time: 3ms
Logest frame time: 18ms
----------------------------------------
 
This is a sample debug output - It displays ever second the number of frames and how long each part took.
The logic handles the events, collisions, etc.
The render time calculates how long it takes to draw all the objects on the screen.
 
----------------------------------------
783 Frames displayed in 1 second 
Logest logic time: 1ms
Logest render time: 3ms
Logest frame time: 4ms
----------------------------------------
 
The differences above denote VSync enabled and not enabled. I have a very high frame rate and the game never has a spike in processing. The rendering is a steady 3-5ms and the logic is always 1ms. The longest frame never exceeds 5ms unless VSync is enabled then each one is 16-18ms.
 
I started out with SDL 1.2, everything ran fine. Decided to implement OpenGL for more control and better frame rate, then the stuttering began. I thought it may be an issue with SDL so I upgraded to SDL2, still no change in the stutter.
 
 
The code I use to load start SDL, init GL, and load PNGs into textures, I have rewritten 2-3 times each. Anything that displays to the screen I have rewritten at least twice. 
 
 
I have taken all the code that is responsible for setting up opengl, sdl, loading an image from a png to gluint, and displaying it on the screen and yanked it out. I have posted in on a github here:
 
 
This code takes a background tile, sticks it in the top left corner, and moves it to the bottom left corner. During the image's journey from corner to corner, you should be able to see the stutter that occurs a couple of times. Even this very basic example has the same problem of stuttering.
 
 

If you have any questions or need additional info, please just ask.

 

I really, really appreciate your guys' help in this! It's the last hurdle to my engine working!

 
--------------------------------------------------------------------------
Systems:
Laptop with 2nd generation intel integrated graphics
Laptop with 1st generation intel integrated graphics
Desktop with i7 920 and 6870 radeon card
 
OS:
Linux - Ubuntu 13.10, 12.04
Windows 7 (mingw, but have also tried vc++ and the issue persists)
 
Each box has a Ubuntu and Windows 7 installation. Libraries and build environments are all sync'd. 
All drivers are up to date, all other games that run openGL work just fine.

#2martinis_shaken

Posted 07 November 2013 - 07:02 AM

My game has an issue with micro stuttering. Every second or two the game "jumps" a little, as if a few frames are missed. There is no tearing of the screen, just a small pause and then the jump forward. The issue occurs whether the character is moving or not, scrolling or not (just more noticeable when scrolling), etc. Without fail, every second or two, the game will just jerk/jump/stutter.
 
The issue is similar to this post, though VSync does not fix the problem.
 
----------------------------------------
60 Frames displayed in 1 second 
Logest logic time: 1ms
Logest render time: 3ms
Logest frame time: 18ms
----------------------------------------
 
This is a sample debug output - It displays ever second the number of frames and how long each part took.
The logic handles the events, collisions, etc.
The render time calculates how long it takes to draw all the objects on the screen.
 
----------------------------------------
783 Frames displayed in 1 second 
Logest logic time: 1ms
Logest render time: 3ms
Logest frame time: 4ms
----------------------------------------
 
The differences above denote VSync enabled and not enabled. I have a very high frame rate and the game never has a spike in processing. The rendering is a steady 3-5ms and the logic is always 1ms. The longest frame never exceeds 5ms unless VSync is enabled then each one is 16-18ms.
 
I started out with SDL 1.2, everything ran fine. Decided to implement OpenGL for more control and better frame rate, then the stuttering began. I thought it may be an issue with SDL so I upgraded to SDL2, still no change in the stutter.
 
 
The code I use to load start SDL, init GL, and load PNGs into textures, I have rewritten 2-3 times each. Anything that displays to the screen I have rewritten at least twice. 
 
 
I have taken all the code that is responsible for setting up opengl, sdl, loading an image from a png to gluint, and displaying it on the screen and yanked it out. I have posted in on a github here:
 
 
 

If you have any questions or need additional info, please just ask.

 

I really, really appreciate your guys' help in this! It's the last hurdle to my engine working!

 
--------------------------------------------------------------------------
Systems:
Laptop with 2nd generation intel integrated graphics
Laptop with 1st generation intel integrated graphics
Desktop with i7 920 and 6870 radeon card
 
OS:
Linux - Ubuntu 13.10, 12.04
Windows 7 (mingw, but have also tried vc++ and the issue persists)
 
Each box has a Ubuntu and Windows 7 installation. Libraries and build environments are all sync'd. 
All drivers are up to date, all other games that run openGL work just fine.

#1martinis_shaken

Posted 06 November 2013 - 07:41 AM

My game has an issue with micro stuttering. Every second or two the game "jumps" a little, as if a few frames are missed. There is no tearing of the screen, just a small pause and then the jump forward. The issue occurs whether the character is moving or not, scrolling or not (just more noticeable when scrolling), etc. Without fail, every second or two, the game will just jerk/jump/stutter.
 
The issue is similar to this post, though VSync does not fix the problem.
 
----------------------------------------
60 Frames displayed in 1 second 
Logest logic time: 1ms
Logest render time: 3ms
Logest frame time: 18ms
----------------------------------------
 
This is a sample debug output - It displays ever second the number of frames and how long each part took.
The logic handles the events, collisions, etc.
The render time calculates how long it takes to draw all the objects on the screen.
 
----------------------------------------
783 Frames displayed in 1 second 
Logest logic time: 1ms
Logest render time: 3ms
Logest frame time: 4ms
----------------------------------------
 
The differences above denote VSync enabled and not enabled. I have a very high frame rate and the game never has a spike in processing. The rendering is a steady 3-5ms and the logic is always 1ms. The longest frame never exceeds 5ms unless VSync is enabled then each one is 16-18ms.
 
 
I started out with SDL 1.2, everything ran fine. Decided to implement OpenGL for more control and better frame rate, then the stuttering began. I thought it may be an issue with SDL so I upgraded to SDL2, still no change in the stutter.
 
 
The code I use to load start SDL, init GL, and load PNGs into textures, I have rewritten 2-3 times each. Anything that displays to the screen I have rewritten at least twice. 
The current code is now very close to the code found in the glfont.c test written by SDL's creator.
 
 
I know this is a lot of code, but it is very easy to follow and a lot of it is stock, simple stuff.
 
 
Set up OpenGL for 2D
107 //Initialize Open GL///////////////////////////////////////////////////
108 bool SDL_GL_Enter2DMode()
109 {
110    /* Note, there may be other things you need to change,
111       depending on how you have your OpenGL state set up.
112    */
113    glPushAttrib(GL_ENABLE_BIT);
114    glDisable(GL_DEPTH_TEST);
115    glDisable(GL_CULL_FACE);
116    glEnable(GL_TEXTURE_2D);
117 
118    /* This allows alpha blending of 2D textures with the scene */
119    glEnable(GL_BLEND);
120    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
121 
122    glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
123 
124    glMatrixMode(GL_PROJECTION);
125    glPushMatrix();
126    glLoadIdentity();
127 
128    glOrtho(0.0, (GLdouble)SCREEN_WIDTH, (GLdouble)SCREEN_HEIGHT, 0.0, 0.0, 1.0);
129 
130    glMatrixMode(GL_MODELVIEW);
131    glPushMatrix();
132    glLoadIdentity();
133 
134    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
135 
136    if( glGetError() != GL_NO_ERROR )
137    {
138       return false;
139    }
140 
141    //If everything initialized
142    return true;
143 
144 }
145 ///////////////////////////////////////////////////////////////////////

Load Textures into a Texture class

172 //Load an image into a GLuint Texture//////////////////////////////////
173 Texture loadImage(string name)
174 {
175    SDL_Surface *surface;
176    surface = IMG_Load(name.c_str());
177 
178    GLuint texture;
179    int w, h;
180    SDL_Surface *image;
181    SDL_Rect area;
182    Uint8  saved_alpha;
183    SDL_BlendMode saved_mode;
184 
185    /* Use the surface width and height expanded to powers of 2 */
186    w = power_of_two(surface->w);
187    h = power_of_two(surface->h);
188 
189    image = SDL_CreateRGBSurface(
190          SDL_SWSURFACE,
191          w, h,
192          32,
193 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
194          0x000000FF,
195          0x0000FF00,
196          0x00FF0000,
197          0xFF000000
198 #else
199          0xFF000000,
200          0x00FF0000,
201          0x0000FF00,
202          0x000000FF
203 #endif
204              );
205    if ( image == NULL ) {
205    if ( image == NULL ) {
206       cerr<<"Failure";
207       exit(1);
208    }
209 
210    /* Save the alpha blending attributes */
211    SDL_GetSurfaceAlphaMod(surface, &saved_alpha);
212    SDL_SetSurfaceAlphaMod(surface, 0xFF);
213    SDL_GetSurfaceBlendMode(surface, &saved_mode);
214    SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
215 
216    /* Copy the surface into the GL texture image */
217    area.x = 0;
218    area.y = 0;
219    area.w = surface->w;
220    area.h = surface->h;
221    SDL_BlitSurface(surface, &area, image, &area);
222 
223    /* Restore the alpha blending attributes */
224    SDL_SetSurfaceAlphaMod(surface, saved_alpha);
225    SDL_SetSurfaceBlendMode(surface, saved_mode);
226 
227    /* Create an OpenGL texture for the image */
228    glGenTextures(1, &texture);
229    glBindTexture(GL_TEXTURE_2D, texture);
230    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
231    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
232    glTexImage2D(GL_TEXTURE_2D,
233            0,
234            GL_RGBA,
235            w, h,
236            0,
237            GL_RGBA,
238            GL_UNSIGNED_BYTE,
239            image->pixels);
240    SDL_FreeSurface(image); /* No longer needed */
241 
242    Texture t(texture, w, h, surface->w, surface->h);
243 
244    SDL_FreeSurface(surface);
245 
246    return t;
247 
248 }
249 //////////////////////////////////////////////////////////////////////
250 

Now here is where the drawing to the OpenGL context happens:

void DisplayScreen::Draw(const Texture& texture, int x, int y, Rect* clip)
{ 
   //Texture coordinates
   GLfloat texTop = 0.f;
   GLfloat texBottom = 1.f;
   GLfloat texLeft = 0.f;
   GLfloat texRight = 1.f;

   //Vertex coordinates
   GLfloat quadWidth = texture.w;
   GLfloat quadHeight = texture.h;

   if( clip != NULL )
   {
      //Texture coordinates
      texLeft = clip->x / texture.w;
      texRight = ( clip->x + clip->w ) / texture.w;
      texTop = clip->y / texture.h;
      texBottom = ( clip->y + clip->h ) / texture.h;

      //Vertex coordinates
      quadWidth = clip->w;
      quadHeight = clip->h;
   }

   // Bind the texture to which subsequent calls refer to
   glBindTexture( GL_TEXTURE_2D, texture.tex);

   glBegin( GL_QUADS );
      glTexCoord2f(  texLeft,    texTop ); glVertex2f(       x,        y );
      glTexCoord2f( texRight,    texTop ); glVertex2f( x +quadWidth,        y );
      glTexCoord2f( texRight, texBottom ); glVertex2f( x +quadWidth, y +quadHeight );
      glTexCoord2f(  texLeft, texBottom ); glVertex2f(       x, y +quadHeight );
   glEnd(); 

}

Regarding this draw function. I have also tried "translating" to the x, y coordinates, drawing the image there and chaning the params in the glTexCoord2f section.

 

 

This is all the code that goes into setting up OpenGL for 2D, loading all the textures, and drawing every one onto the screen. Since I have upgraded from SDL 1.2 to SDL 2 and since a decent number of things changed, I suspect the issue lies within my OpenGL code

 

 

If you have any questions or need additional info, please just ask.

 

I really, really appreciate your guys' help in this! It's the last hurdle to my engine working!

 
 
 
--------------------------------------------------------------------------
Systems:
Laptop with 2nd generation intel integrated graphics
Laptop with 1st generation intel integrated graphics
Desktop with i7 920 and 6870 radeon card
 
OS:
Linux - Ubuntu 13.10, 12.04
Windows 7 (mingw, but have also tried vc++ and the issue persists)
 
Each box has a Ubuntu and Windows 7 installation. Libraries and build environments are all sync'd. 
All drivers are up to date, all other games that run openGL work just fine.
 

PARTNERS