Fast Frame Rates but Still Ugly

Posts: 100
Joined: 2006.05
Post: #16
1) Windowed.
2) ATI 9800 Pro
3) 20" Studio Display
4) Very simple timing method. I just simply calculate the time difference between the last frame and the current frame (Using GetCurrentEventTime() [Using Carbon]) and I use that number to multiply all my increment values (All increments are in units per seconds [eg. degree's rotation per second]).

1) I dunno about that, I wouldn't think there would be so much of a performance hit considering I'm on a Dual 2GHz G5 with 1GB RAM and only about 4 other small apps running... Even when I click inside the menus and move around it behaves exactly the same....
2) I'm under 10.3.4 currently, and I only have one OpenGL context...
3) I don't fix the rate of my frames at all, since everything is purely time based... Not exactly sure what you mean there.
4) That pretty much is my method, I let the app run as fast as possible and do everything according to the time difference with the last frame and the VBL sync does whatever it wants....
Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #17
So 3) and 4) don't apply. 1) and 2) still do. It doesn't matter how fast your CPU is-- the ATI drivers are broken. You might only have one context, but the window manager has dozens.

Try going fullscreen, capturing the display. Always solves my VBL problems.
Quote this message in a reply
Posts: 156
Joined: 2002.11
Post: #18
In my engine, I just setup a double buffered context and then I call aglSwapBuffers () or CGLFlushDrawable () in the end of my drawing/blitting routines. It seems these two commands swap the back and front buffers when the screen is being resfreshed. I experience no tearing or any artifacts whatsoever.
Quote this message in a reply
Posts: 2
Joined: 2010.11
Post: #19
Nick, can I see your code? I can't get mine to work. I am using SDL and openGL in C.
Quote this message in a reply
Posts: 1,066
Joined: 2004.07
Post: #20
Sure here you go (it's in C++ for whatever it matters):

#include <OpenGL/OpenGL.h>
#include "SDL_opengl.h"
#include "SDL.h"

[then a buch of stuff]
Sorry about the large mass of code below. I thought it might help to see all of the initialization code I'm using. Anyways the vsync comes in pretty much 5 lines from the end.

creates the window
void CreateMyWindow(const char * strWindowName, int width, int height, int VideoFlags)
    MainWindow = SDL_SetVideoMode(width, height, SCREEN_DEPTH, VideoFlags);     // SCREEN_DEPTH is macro for bits per pixel

    if( MainWindow == NULL )                            // if window creation failed
        cerr << "Failed to Create Window : " << SDL_GetError() << endl;         // report error

    SDL_WM_SetCaption(strWindowName, strWindowName);    // set the window caption (first argument) and icon caption (2nd arg)

sets the pixel format for OpenGL and video flags for SDL
void SetupPixelFormat(void)
    VideoFlags    = SDL_OPENGL; //it's an openGL window
    VideoFlags   |= SDL_HWPALETTE; //exclusive access to hardware colour palette
    VideoFlags   |= SDL_RESIZABLE; //the window must be resizeable
    VideoFlags   |= SDL_FULLSCREEN; //make the window fullscreen

    const SDL_VideoInfo * VideoInfo = SDL_GetVideoInfo();     // query SDL for information about our video hardware

    if(VideoInfo == NULL)                                     // if this query fails
        cerr << "Failed getting Video Info : " << SDL_GetError() << endl;          // report error

    if(VideoInfo -> hw_available) // is it a hardware surface
        VideoFlags |= SDL_HWSURFACE;
        VideoFlags |= SDL_SWSURFACE;

    if(VideoInfo -> blit_hw) // is hardware blitting available
        VideoFlags |= SDL_HWACCEL;

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // tell SDL that the GL drawing is going to be double buffered
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,   SCREEN_DEPTH); // size of depth buffer
    SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); // we aren't going to use the stencil buffer
    SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0); // this and the next three lines set the bits allocated per pixel -
    SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0); // - for the accumulation buffer to 0
    SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0);
    SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0);

resizes the viewport for OpenGL
void SizeOpenGLScreen(int width, int height) // Initialize The GL Window
    if (height==0) // Prevent A Divide By Zero error
        height=1; // Make the Height Equal One

    glViewport(0,0,width,height); // Make our viewport the whole window
                                  // We could make the view smaller inside
                                  // Our window if we wanted too.
                                  // The glViewport takes (x, y, width, height)
                                  // This basically means, what our our drawing boundries

    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    // The parameters are:
    // (view angle, aspect ration of the width to the height,
    //  The closest distance to the camera before it clips,
                  // FOV        // Ratio                //  The farthest distance before it stops drawing)
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, .5f ,150.0f);

    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glLoadIdentity(); // Reset The Modelview Matrix

initializes OpenGL
void InitializeGL(int width, int height)
    glEnable(GL_DEPTH_TEST);                                // Enables Depth Testing
    SizeOpenGLScreen(width, height);                        // resize the OpenGL Viewport to the given height and width

create the window and call the initialization functions
int main(int argc, char*argv[])
    // print user instructions
    cout << " Hit the F1 key to Toggle between Fullscreen and windowed mode" << endl;
    cout << " Hit ESC to quit" << endl;

    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) // try to initialize SDL video module
        cerr << "Failed initializing SDL Video : " << SDL_GetError() << endl; // report error if it fails
        return 1; // we use this instead of Quit because SDL isn't yet initialized

    // Set up the format for the pixels of the OpenGL drawing surface
    // Create our window, we pass caption for the window, the width, height and video flags required
    CreateMyWindow(" - Camera Strafing", SCREEN_WIDTH, SCREEN_HEIGHT, VideoFlags);

    // Initializes our OpenGL drawing surface
    //sync the frame rate with the screen refresh
    long VBL = 1;
    CGLSetParameter(CGLGetCurrentContext(),  kCGLCPSwapInterval, &VBL);
    // Run our main loop

    // quit main returning success
    return 0;
Quote this message in a reply
Posts: 2
Joined: 2010.11
Post: #21
Thanks, I got my code to work.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Slowing Frame Rates and Display Lists Nick 4 4,708 Mar 27, 2005 06:08 AM
Last Post: wadesworld
  fast billboards reubert 2 3,974 Oct 7, 2004 04:41 AM
Last Post: OneSadCookie
  GL_LINE_SMOOTH looks ugly Vertizor 9 9,306 Sep 21, 2004 11:30 PM
Last Post: arekkusu
  Too fast! Silden 7 6,719 Apr 16, 2003 02:40 PM
Last Post: Mars_999
  how fast should this be? <seb> 3 5,488 Feb 25, 2003 12:51 PM
Last Post: <seb>