![]() |
|
|
(#16)
|
|
|
Posts: n/a
|
2004.08.11, 12:38 AM
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.... |
|
|
|
|
(#17)
|
|
|
Member
Posts: 1,334
Join Date: 2002.10
Location: Sunnyvale, CA
|
2004.08.11, 12:46 AM
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. |
|
|
|
|
(#18)
|
|
|
Member
Posts: 213
Join Date: 2002.11
Location: TX, USA
|
2004.08.16, 12:51 AM
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.
|
|
|
|
|
(#19)
|
|
|
Posts: n/a
|
2004.08.16, 07:36 AM
Nick, can I see your code? I can't get mine to work. I am using SDL and openGL in C.
|
|
|
|
|
(#20)
|
|
|
Member
Posts: 1,227
Join Date: 2004.07
Location: Seattle, Washington
|
2004.08.16, 07:58 PM
Sure here you go (it's in C++ for whatever it matters):
Code:
#include <OpenGL/OpenGL.h> #include "SDL_opengl.h" #include "SDL.h" 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. Code:
/*
CreateMyWindow
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
Quit(0);
}
SDL_WM_SetCaption(strWindowName, strWindowName); // set the window caption (first argument) and icon caption (2nd arg)
}
/*
SetupPixelFormat
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
Quit(0);
}
if(VideoInfo -> hw_available) // is it a hardware surface
VideoFlags |= SDL_HWSURFACE;
else
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);
}
/*
SizeOpenGLScreen
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
}
/*
InitializeGL
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
}
/*
main
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
SetupPixelFormat();
// Create our window, we pass caption for the window, the width, height and video flags required
CreateMyWindow("www.GameTutorials.com - Camera Strafing", SCREEN_WIDTH, SCREEN_HEIGHT, VideoFlags);
// Initializes our OpenGL drawing surface
Init();
//sync the frame rate with the screen refresh
long VBL = 1;
CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
// Run our main loop
MainLoop();
// quit main returning success
return 0;
}
|
|
|
|
|
(#21)
|
|
|
Posts: n/a
|
2004.08.17, 02:50 PM
Thanks, I got my code to work.
|
|
|
|
| Thread Tools | |
| Display Modes | |
|
|