• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
andrew111

Jerky movement when vsync turned on (wglSwapIntervalEXT).

23 posts in this topic

Hi, I've been searching previous posts here, but I can't find anything to explain my problem. My problem is that with vsync on, my movement is very jerky. I enabled vsync in my program like so:
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
if(wglSwapIntervalEXT) {
	wglSwapIntervalEXT(1);
} else {	
	std::cout << "No vsync";
}
I am using win32 api for my window. My movement is based on deltaTime. I am using the QueryPerformanceCounter to calculate the deltaTime. Am I missing something here? I haven't been able to find any difference between my vsync code and other peoples'. Thanks.
0

Share this post


Link to post
Share on other sites
You need to interpolate between one frame to the next or else you will always have jerky motion even if you are moving based on delta time.

I have a video in the Physics series that describes this in details (see space ship motion).
0

Share this post


Link to post
Share on other sites
Like if I move forward it will freeze for a quarter of a second and then move, though for some reason it seems to be doing with less frequency now.

My movement code is:



float walk = (keyDown(VkKeyScan(k[0]))?-1.0f:0.0f)+ (keyDown(VkKeyScan(k[2]))?1.0f:0.0f);
float strafe = (keyDown(VkKeyScan(k[1]))?-1.0f:0.0f)+ (keyDown(VkKeyScan(k[3]))?1.0f:0.0f);
Vector3 dir = camera.front*walk*-1.0f + camera.right*strafe;

if(dir.length2()) {
camera.position += dir.normalise()*6.0f*dt;
}




My timer is:


QueryPerformanceCounter((LARGE_INTEGER*)&startTime);

/*game run code*/

_int64 freq;
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);

_int64 stopTime;
QueryPerformanceCounter((LARGE_INTEGER*)&stopTime);

dt = (startTime)?float(stopTime-startTime)/(float)freq:0;




Edit:

I just noticed that the jerkiness stopped when I outputted text to the console window every loop.

0

Share this post


Link to post
Share on other sites
are you by chance moving the mouse whilst the jerkiness occurs?

Ive noticed that.

Also try a difference timer than QueryPerformanceFrequency, eg timeGetTime() + report back here your results
cheers zed
0

Share this post


Link to post
Share on other sites
Yeah I've got that problem too.

Quote:
Original post by zedz
Also try a difference timer than QueryPerformanceFrequency, eg timeGetTime() + report back here your results
cheers zed



Ok I'll let you know when I get home.
0

Share this post


Link to post
Share on other sites
Ok so same problem with using timeGetTime().

Also the problem is more like this:
* moving the mouse seems a little shakey or jerky, but not too bad
* movement pauses for a moment every now and then, and then jumps forward to pos+=movementDir*deltaTime
* when I output the dt every loop to console, the jumping on the movement seems to disapear
* with vsync off I get finer movements, and not so with it on

I'll post most of the related code:

This is my winmain code

/*#if defined(_DEBUG)
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif*/


#pragma comment(linker, "/subsystem:\"console\" /entry:\"WinMainCRTStartup\"")

#include <windows.h>
#include <GL/gl.h>
#include "Timer.h"
#include "Main.h"
#include "Window.h"
#include <iostream>
#include "wglext.h"

//
HWND windowHandle;

//
RECT clientRect;
RECT windowRect;

//
BYTE keyState[256];
BYTE keyPrevState[256];

//
POINT cursor = {0,0};
POINT prevCursor = {0,0};

float mx = 0, my = 0;

//
Timer timer;

//
bool lockCursorEnabled = false;

//
//
int Window::clientWidth() {
return clientRect.right;
}
int Window::clientHeight() {
return clientRect.bottom;
}

//
bool Window::keyDown(int key) {
return (keyState[key] & 0x80) && 1;
}
bool Window::keyUpped(int key) {
return (!(keyState[key] & 0x80) && (keyPrevState[key] & 0x80));
}
bool Window::keyDowned(int key) {
return ((keyState[key] & 0x80) && !(keyPrevState[key] & 0x80));
}

//
int Window::cursorX() {
return cursor.x;
}
int Window::cursorY() {
return cursor.y;
}

//
float Window::mouseMoveX() {
return mx;
}
float Window::mouseMoveY() {
return my;
}
//
float Window::deltaTime() {

return timer.get();
}

//
int Window::left() {
return windowRect.left;
}
int Window::top() {
return windowRect.top;
}
int Window::width() {
return windowRect.right-windowRect.left;
}
int Window::height() {
return windowRect.bottom-windowRect.top;
}

//
void Window::lockCursor(bool enabled) {
lockCursorEnabled = enabled;

if(!enabled) {
ClipCursor(0);
}

}

//
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
//for mouse move
if(msg == WM_INPUT) {
UINT dwSize = 40;
static BYTE lpb[40];
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));

RAWINPUT* raw = (RAWINPUT*)lpb;

if (raw->header.dwType == RIM_TYPEMOUSE) {
int x =raw->data.mouse.lLastX;
int y = raw->data.mouse.lLastY;

mx = (float)x;
my = (float)y;
}
}
static bool in = false;

if(msg == WM_MOUSEMOVE) {
in = true;

}

if(msg == WM_MOUSELEAVE) {
in = false;
}

//escape key
if(msg == WM_KEYDOWN && wParam == VK_ESCAPE) {
DestroyWindow(hWnd);
}

//
if(msg == WM_KEYDOWN && wParam == VK_CONTROL) {

}

//close button
if(msg == WM_DESTROY) {
PostQuitMessage(0);
return 0;
}

//
return DefWindowProc(hWnd, msg, wParam, lParam);
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
/*#if defined(_DEBUG)
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)|_CRTDBG_DELAY_FREE_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
#endif*/


//
const char title[] = "title";
int windowWidth = 1024;
int windowHeight = 800;

//desktop size
RECT desktopRect;
GetWindowRect(GetDesktopWindow(), &desktopRect);

//init window
WNDCLASS wc = {CS_CLASSDC|CS_DBLCLKS, WndProc, 0, 0, hInstance, 0, LoadCursor(0, IDC_ARROW), 0, 0, "abc"};
RegisterClass(&wc);
windowHandle = CreateWindow(wc.lpszClassName, title,
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_THICKFRAME|WS_VISIBLE,
(desktopRect.right-windowWidth)/2/*CW_USEDEFAULT*/, (desktopRect.bottom-windowHeight)/2/*CW_USEDEFAULT*/, windowWidth, windowHeight, 0, 0, hInstance, 0);


//window dc
HDC windowDc = GetDC(windowHandle);

//for mouse move
RAWINPUTDEVICE Rid[1];
Rid[0].usUsagePage = 0x01; //HID_USAGE_PAGE_GENERIC
Rid[0].usUsage = 0x02; //HID_USAGE_GENERIC_MOUSE
Rid[0].dwFlags = RIDEV_INPUTSINK;
Rid[0].hwndTarget = windowHandle;
RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));

//init opengl
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory( &pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat(windowDc, &pfd);
SetPixelFormat(windowDc, iFormat, &pfd);
SwapBuffers(windowDc);
HGLRC rc = wglCreateContext(windowDc);
wglMakeCurrent(windowDc, rc);

//turn on vsync
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) wglGetProcAddress("wglGetSwapIntervalEXT");

if(!wglSwapIntervalEXT) {
std::cout << "No vsync";
} else {
wglSwapIntervalEXT(1);
std::cout << "vsync " << wglGetSwapIntervalEXT() << std::endl;
}

//
//init key state
ZeroMemory(keyState, sizeof(keyState));
ZeroMemory(keyPrevState, sizeof(keyPrevState));


//
if(Main::create()) {


//
MSG msg;
ZeroMemory(&msg, sizeof(msg));

while(msg.message != WM_QUIT) {
if(IsIconic(windowHandle) || (GetForegroundWindow() != windowHandle /*&& GetForegroundWindow() != GetConsoleWindow()*/)) {
if(GetMessage(&msg, 0,0,0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

//
ClipCursor(0);

//
//mx = 0;
//my = 0;
} else {
if(PeekMessage(&msg, 0,0,0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
//
timer.stop(); //edit
timer.start();

//
GetClientRect(windowHandle, &clientRect);
GetWindowRect(windowHandle, &windowRect);

//keystate
memcpy(&keyPrevState, &keyState, sizeof(keyPrevState));
GetKeyboardState(keyState);

//cursor
if(!lockCursorEnabled) {
prevCursor = cursor;
GetCursorPos(&cursor);
ScreenToClient(windowHandle, &cursor);
}

//
if(lockCursorEnabled) {
POINT clientTopLeft = {0,0};
POINT clientBottomRight = {clientRect.right, clientRect.bottom};
ClientToScreen(windowHandle, &clientTopLeft);
ClientToScreen(windowHandle, &clientBottomRight);
RECT clipRect;
SetRect(&clipRect, clientTopLeft.x, clientTopLeft.y, clientBottomRight.x, clientBottomRight.y);
ClipCursor(&clipRect);

POINT clientMid = cursor;//{clientRect.right/2, clientRect.bottom/2};
ClientToScreen(windowHandle, &clientMid);
SetCursorPos(clientMid.x, clientMid.y);
}

//


if(!Main::run()) {
break;
}

//
mx=0;
my=0;

//
SwapBuffers(windowDc);



}
}
}
}

//
Main::destroy();

//cleanup opengl
wglMakeCurrent(0, 0);
wglDeleteContext(rc);

//
ReleaseDC(windowHandle, windowDc);

//
OutputDebugString("\nexited.\n\n");
//system("pause");

return 0;
}






And this is my movement code

void runPlayer() {
static bool mouseView = false;
static bool mouseRightView = false;

int lookKey = VK_LBUTTON;
int heightKey = VK_RBUTTON;

if(Window::keyDowned(lookKey) || Window::keyDowned(heightKey)) {
Window::lockCursor(true);
ShowCursor(false);
}

if(Window::keyUpped(lookKey) || Window::keyUpped(heightKey)) {
Window::lockCursor(false);
ShowCursor(true);
}

if(Window::keyDowned(lookKey)) {
mouseView = true;
}

if(Window::keyUpped(lookKey)) {
mouseView = false;
}

if(Window::keyDowned(heightKey)) {
mouseRightView = true;
}

if(Window::keyUpped(heightKey)) {
mouseRightView = false;
}

const char *k =
"esdf"
// "wasd"
;

//
float walk = (Window::keyDown(VkKeyScan(k[0]))?-1.0f:0.0f)+ (Window::keyDown(VkKeyScan(k[2]))?1.0f:0.0f);
float strafe = (Window::keyDown(VkKeyScan(k[1]))?-1.0f:0.0f)+ (Window::keyDown(VkKeyScan(k[3]))?1.0f:0.0f);

Vector3 dir = camera.front*walk*-1.0f + camera.right*strafe;

if(mouseRightView) {
dir.y = 0;
}

if(dir.length2()) {
camera.position += dir.normalise()*((Window::keyDown(VK_SHIFT))?26.0f:13.0f)*Window::deltaTime();
}

const float lookSpeed = 3.0f;

camera.rotateAngle += ((Window::keyDown(VK_UP)?1.0f:0.0f)+ (Window::keyDown(VK_DOWN)?-1.0f:0.0f))*lookSpeed*Window::deltaTime();
camera.aroundAngle += ((Window::keyDown(VK_LEFT)?1.0f:0.0f)+ (Window::keyDown(VK_RIGHT)?-1.0f:0.0f))*lookSpeed*Window::deltaTime();

static float yawVel = 0;
static float pitchVel = 0;

if(mouseView || mouseRightView) {
camera.aroundAngle -= (float)Window::mouseMoveX()*lookSpeed*Window::deltaTime();//*0.5f;
camera.rotateAngle -= (float)Window::mouseMoveY()*lookSpeed*Window::deltaTime();//*0.5f;
}

const float pi2 = 1.5707f;

if(camera.rotateAngle > pi2) {
camera.rotateAngle = pi2;
}

if(camera.rotateAngle < -pi2) {
camera.rotateAngle = -pi2;
}

camera.calculate();
}






The camera code is just

Camera::Camera()
: transform(4), aroundAngle(0), aroundBack(0), rotateAngle(0)
{
transform.setIdentity();
}
void Camera::calculate() {
Camera::Camera()
: transform(4), aroundAngle(0), aroundBack(0), rotateAngle(0)
{
transform.setIdentity();
}
void Camera::calculate() {
Matrix positionMat(4), rotateMat(4), aroundMat(4), aroundBackMat(4);

positionMat.setPosition(position);
rotateMat.setRotation(rotateAxis, rotateAngle);
aroundMat.setRotation(aroundAxis, aroundAngle);
aroundBackMat.setPosition(Vector3(0,0,aroundBack));

transform = (positionMat*(aroundMat*aroundBackMat))*rotateMat;

//
front = transform.getZAxis()*-1.0f;
at = position + front;
right = transform.getXAxis();
up = transform.getYAxis();
}






Also the Main::run() is


bool Main::run() {
std::cout << Window::deltaTime() << std::endl;

runPlayer();

//
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, Window::clientWidth(), Window::clientHeight());

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, float(Window::clientWidth())/float(Window::clientHeight()), 0.1f, 950);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//sky
glUseProgram(0);

glPushMatrix();
gluLookAt(0,0,0, camera.front.x,camera.front.y,camera.front.z, camera.up.x,camera.up.y,camera.up.z);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, skyTexture);
renderSky();
glDisable(GL_TEXTURE_CUBE_MAP);
glPopMatrix();

//
gluLookAt(camera.position.x,camera.position.y,camera.position.z, camera.at.x,camera.at.y,camera.at.z, camera.up.x,camera.up.y,camera.up.z);

//light

glPushMatrix();
glTranslatef(2,3,0);
Light light;
light.position[3] = 1;
light.run(GL_LIGHT0);
light.render(quadratic);
glPopMatrix();

//test
glPushMatrix();
glColor4f(1,1,1,1);
testMesh->render();
glPopMatrix();

//other
glUseProgram(0);
runFps();
renderAxises();

//
return true;
}



Thanks.

[Edited by - andrew111 on August 15, 2009 12:24:27 AM]
0

Share this post


Link to post
Share on other sites
I was just about to suggest to turn vsync off + then I notice having it on causes the problem (from your post)

>>My movement is based on deltaTime.

u say your FPS is 800-1200, in this case u really should use a fixed loop update, i.e. ditch the deltaTime stuff

something else to try is stick a sleep(1)/SDL_Delay(1); command somewhere in your main loop (so it gets called once per bufferswap)
0

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
I was just about to suggest to turn vsync off + then I notice having it on causes the problem (from your post)

>>My movement is based on deltaTime.

u say your FPS is 800-1200, in this case u really should use a fixed loop update, i.e. ditch the deltaTime stuff


But how would I get consistent movement without delta time?

Quote:
Original post by zedz
something else to try is stick a sleep(1)/SDL_Delay(1); command somewhere in your main loop (so it gets called once per bufferswap)


I tried that, but it didn't seem to make much difference.

Back when I was using GLUT, that seemed to help stop it from using too much of the cpu, but it doesn't help with my current code especially when vsync is off, it doesn't stop it from overworking the cpu.
0

Share this post


Link to post
Share on other sites
>>But how would I get consistent movement without delta time?

http://www.flipcode.com/archives/Main_Loop_with_Fixed_Time_Steps.shtml

in GameTickRun();
u update all the movement, all movement will be consistent no matter what the FPS, this is a better method than what u have at the moment with the variable 'delta time'

>>but it doesn't help with my current code especially when vsync is off, it doesn't stop it from overworking the cpu.

try with delay(10) then, if that doesnt make CPU usage go down then something is seriously screwed
0

Share this post


Link to post
Share on other sites
Quote:
Original post by andrew111
Quote:
Original post by zedz
I was just about to suggest to turn vsync off + then I notice having it on causes the problem (from your post)

>>My movement is based on deltaTime.

u say your FPS is 800-1200, in this case u really should use a fixed loop update, i.e. ditch the deltaTime stuff


But how would I get consistent movement without delta time?

Quote:
Original post by zedz
something else to try is stick a sleep(1)/SDL_Delay(1); command somewhere in your main loop (so it gets called once per bufferswap)


I tried that, but it didn't seem to make much difference.

Back when I was using GLUT, that seemed to help stop it from using too much of the cpu, but it doesn't help with my current code especially when vsync is off, it doesn't stop it from overworking the cpu.


This sounds like a common problem with coupled render/logic rates. With VSync off you are running so many updates on a much finer time delta that anamolies with the timer likely aren't visually noticeable, whereas with the hard locked 60 FPS (and 16 ms time step) anamolies result in visible sluggishness.

There are numerous ways to decouple your render/logic rates -- the method I prefer which gives very smooth results on a wide variety of machines is setting a very fast logic update rate (like 200 FPS or 5 ms) but maintaining the time based update thus avoiding a need for accumulation. This is not ideal for physics heavy simulations or games where the logic phase is not considerably faster than the render phase. For most other games the result is liquid smooth updating.


while(ApplicationActive)
{
T()->Update();

int CurrentDMS = (int)T()->GetRealDMS();
int LogicDMS;

while(CurrentDMS > 0)
{
//Calculate our logic delta
LogicDMS = min(CurrentDMS, LOGIC_RATE);
Control::SetLogicRate(LogicDMS);

//Logic Updates
ApplicationUpdate();
Control::Process();

//Decrement our real delta
CurrentDMS -= LOGIC_RATE;
}

//Render Phase
PostUpdate();
}

0

Share this post


Link to post
Share on other sites
just thought of something
I have seen with nvidia + enabling the nvidia icon in the window title (nview or something) very jerky movement, the app will freeze for a 1/10 sec or so every so often, disabling nview fixes it
0

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz

in GameTickRun();
u update all the movement, all movement will be consistent no matter what the FPS, this is a better method than what u have at the moment with the variable 'delta time'



Quote:
Original post by shadowcomplex

This sounds like a common problem with coupled render/logic rates. With VSync off you are running so many updates on a much finer time delta that anamolies with the timer likely aren't visually noticeable, whereas with the hard locked 60 FPS (and 16 ms time step) anamolies result in visible sluggishness.



I'm implementing the tick approach now,




Quote:
Original post by zedz
just thought of something
I have seen with nvidia + enabling the nvidia icon in the window title (nview or something) very jerky movement, the app will freeze for a 1/10 sec or so every so often, disabling nview fixes it


I have an ATI card on this machine, so I dunno if they have anything similar.

[Edited by - andrew111 on August 15, 2009 12:07:32 AM]
0

Share this post


Link to post
Share on other sites
Hmm I just ran the program on my brother's machine who has an ATI radeon 4890, and its smooth.
My card is ATI radeon 4850.

So I dunno.


Also I implemented the ticker like so:

Ticker::Ticker(float length)
: length(length), ticks(0), t(0)
{
}
void Ticker::run(float deltaTime) {
ticks = 0;
t+= deltaTime;

while(t > length) {
t-= length;
ticks++;
}
}
int Ticker::get() {
return ticks;
}



bool Main::run() {
ticker.run(Window::deltaTime());

for(int i=0;i<ticker.get();i++) {
runPlayer();
}

//
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, Window::clientWidth(), Window::clientHeight());
..
}

0

Share this post


Link to post
Share on other sites
Quote:
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress( "wglSwapIntervalEXT" );
if(wglSwapIntervalEXT) {
wglSwapIntervalEXT(1);
} else {
std::cout << "No vsync";
}
Am I missing something here? I haven't been able to find any difference between my vsync code and other peoples'.
Nice code, it's really yours? =) (bad coding style btw).

Quote:
My problem is that with vsync on, my movement is very jerky.
It should be.

Quote:
I just noticed that the jerkiness stopped when I outputted text to the console window every loop.
it is dependning you your window size. Make it smaller and it will still go jerky.

First you have no reason to run with vsync off. In any serious game you will have so much things to do so you won't have time enough to do everything. It is no idea to render more frames than you can't display anyway. It is better to spend that time in your ai/physics/shaders than on trying to update the screen.

Btw, what animation are you running? GL gears in simplest window I posted in some other thread? That was just a simple test to play with timers and message pump, nothing really ready to use. Also animation goiong on in glgears is too simple to be measure of anything else but time taken in swapp buffers routine. There is no really work for your graphic card in that demo. If you simply change size of the window you should see drastic change in fps; say from 1000 fps in fullscreen to 6000 at size 300x300.
0

Share this post


Link to post
Share on other sites



Quote:
Original post by joe_bubamara
Nice code, it's really yours? =) (bad coding style btw).

Bad coding style? doesnt look too bad to me

Its partly cut and paste but modified a little.


....
Anyway I wanted vsync on because it was running too fast.

I've got a feeling the jerkiness is something to do with my computer since a different computer I tested the program on didn't have the same problem. But my computer runs retail games fine, eg crysis. So I'm justing doing some testing atm.
0

Share this post


Link to post
Share on other sites
Quote:
Its partly cut and paste but modified a little.
mmm .... :-)

Quote:
Bad coding style? doesnt look too bad to me

it isn't; but it is commonly considered better coding style if you write something like this:

if(wglSwapIntervalEXT != 0)
0

Share this post


Link to post
Share on other sites
I am having the same problem as the OP. I know exactly what he means. I think I know why.

I have an ATI Radeon 4670, and this problem occurs only on this computer. The same .exes have no such problems on all of my other computers (with different video cards).

Basically, what happens is that with V-sync off, I get smooth 300+ FPS, but with V-sync, it kinda caps it to 60, but it's not consistent.

I've measured the times between frames with V-sync on, and it looks like this:

[code]m_dTimePassed 15.628
m_dTimePassed 15.621
m_dTimePassed 15.683
m_dTimePassed 31.219
m_dTimePassed 01.551
m_dTimePassed 29.697
m_dTimePassed 15.609
m_dTimePassed 15.679
m_dTimePassed 56.016
m_dTimePassed 19.726
m_dTimePassed 14.381
m_dTimePassed 01.558
m_dTimePassed 01.537
m_dTimePassed 01.944
m_dTimePassed 14.146
m_dTimePassed 15.634
m_dTimePassed 15.616
m_dTimePassed 15.731
m_dTimePassed 31.157
m_dTimePassed 15.606
m_dTimePassed 15.716
m_dTimePassed 15.533
m_dTimePassed 15.726
m_dTimePassed 15.532
m_dTimePassed 15.670
m_dTimePassed 15.578
m_dTimePassed 15.686[/code]

As you can see, it's a mess. It should be roughly 16.666 ms (1000/60) between every frame. Instead, sometimes a single frame is displayed for duration of 2 or 3 frames, then it quickly renders 2-3 frames in a row without waiting...

I'm going to conclude (for now) it's a driver issue for these particular ATI graphics card series (4600/4800).
0

Share this post


Link to post
Share on other sites
I've tried a few more things, and found a software-side fix (band-aid?).

Putting a glFinish() call right before SwapBuffers() makes this stuttering problem go away 99% of the time (there are still a few occasional frame skips).

Putting a glFinish() call right AFTER SwapBuffers() makes it go away 99.99% (or 100%, hard to say) of the time.

It makes no sense to me why you should put glFinish() right after SwapBuffers(), yet it helps this problem go away... So it's definitely a weird ATI driver issue as far as I can tell.
1

Share this post


Link to post
Share on other sites
How could it be a ATI driver issue? Are other programs running like that? Also, this thread is 2 years old. I was wondering why my name was the second post. So please, create a new thread. There is no point in bringing up old threads from the grave.
0

Share this post


Link to post
Share on other sites
Yes, this is an old thread, but I'm experiencing exactly the same issue as OP. Even with today's drivers (although they're probably not really updating the drivers for Radeon HD 4000 series cards in the latest Catalyst driver packages).

It was the 4th result on Google for ATI and wglSwapIntervalEXT. So I hope it helps others.

[quote name='V-man' timestamp='1310952164' post='4836575'][color="#1C2837"][size="2"]How could it be a ATI driver issue? [/size][/color][color="#1C2837"][size="2"]Are other programs running like that?[/size][/color][color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color][color="#1C2837"][size="2"]The same .exe runs just fine on other computers with nvidia video cards, and Vsync enabled. It seems DirectX programs aren't affected.[/size][/color]
0

Share this post


Link to post
Share on other sites
[quote name='shurcool' timestamp='1310959966' post='4836618']
Yes, this is an old thread, but I'm experiencing exactly the same issue as OP. Even with today's drivers (although they're probably not really updating the drivers for Radeon HD 4000 series cards in the latest Catalyst driver packages).

It was the 4th result on Google for ATI and wglSwapIntervalEXT. So I hope it helps others.

[quote name='V-man' timestamp='1310952164' post='4836575'][color="#1c2837"][size="2"]How could it be a ATI driver issue? [/size][/color][color="#1c2837"][size="2"]Are other programs running like that?[/size][/color][color="#1c2837"][size="2"][/quote][/size][/color]
[color="#1c2837"][size="2"]The same .exe runs just fine on other computers with nvidia video cards, and Vsync enabled. It seems DirectX programs aren't affected.[/size][/color]
[/quote]

If it is a OpenGL problem, then run other GL games such as the demo version of Quake 3, Doom 3, American Mcgee's Alice, Serious Sam 1
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0