# Ripples in the Image

This topic is 4907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone. I use glut library and try to make some simple game. And I have a following problem. When I control the moving of my "ship" made of textured quad across the screen I can notice occasional ripples in it when it is rendered (especially when the image is perfectly aligned horizontally). I don't use anything to measure framerate for now. But I assume it must be very high based on my PC configuration and the simplicity of my project. So why does it happen? What can cause this and how to get rid of it? Thank you.

##### Share on other sites
It's difficult to tell from your description, but what you describe may be what is known as "tearing". This is usually caused by not synchronising to the vertical refresh. (In other words: VSync is off in either your program or the graphics driver).

##### Share on other sites
And how should I turn it on in the application, using something like glEnable? But with what parameter? Cause In my display driver settings both horizontal and vertical synchronisation are on.

##### Share on other sites
Ok, I have count the frame rate and it is about 2000. Is my game not running smooth because of the refreshing of the monitor that can't deal with some leftover frames or what?

##### Share on other sites
"horizontal synchronisation" suggests you are reading the wrong setting.

What VSync does is time the backbuffer switch to when the monitors beam is moving back to the top. If you don't do this, the front buffer can be changed while it is being drawn on the screen.

This means the top of the screen will show the old frame, while the bottom will show the new frame. Fast moving objects (or the whole screen if there is scrolling) can appear to tear along the dividing line, as they have moved several pixels out of alignment with the top.

At 2000 frames per second you could potentially be doing this many times for each "frame" that is actually drawn on the monitor. Try taking a screenshot of this tearing (and post it here). If you can see the distortion in the screenshot, it's not a VSync issue.

##### Share on other sites
There is no distortion on the screenshot. So I guess this should be solved inside the application. So is it because my app rerenders as often as 2k times a second?

##### Share on other sites
You could, depending on what OS you have, solve the problem by activating V-Sync in your graphics card options.

If you are disabling V-Sync via your application, you should either have an option to toggle in on/off or remove it entirely.

##### Share on other sites
I tell you, it is active. I have an ATI graphics card, and its driver has control panel. And the only tab in it where you could change Vsync option is the "monitors" tab. I tried to turn it off and turn it back on. Nothing really changes. And other stuff that was written in glut runs very smooth. I just want to know what am I doing wrong if I get these stupid flickers. I haven't turned this vsync off in the app intentionally and I assume it is on by default.
As I said my app is written in glut.

#include "classes.h"Vessel ship(screenWidth/2, screenHeight/2, 6, 2);int frames;void myInit(void) {	glClearColor(0.0, 0.0, 0.0, 0.0);	glClear(GL_COLOR_BUFFER_BIT);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D(0.0, 640.0, 0.0, 480.0);	}void myDisplay(void) {	ship.update();	Projectile::propell();	glClear(GL_COLOR_BUFFER_BIT);	ship.drawtexture();	Projectile::draw();	glutSwapBuffers();	Projectile::searchdelete();	tweak=(tweak+1)%20;	frames++;	}void timer(int value) {	printf("%d framez\n", frames);	}void myKeyboard(unsigned char c, int x, int y) {	switch(c) {		case 'w': ship.set_w(true); break;		case 's': ship.set_s(true); break;		case 'a': ship.set_a(true); break;		case 'd': ship.set_d(true); break;		case ' ': Projectile::add(ship); break;		}	};void myKeyup(unsigned char c, int x, int y) {	switch(c) {		case 'w': ship.set_w(false); break;		case 's': ship.set_s(false); break;		case 'a': ship.set_a(false); break;		case 'd': ship.set_d(false); break;		}	}int main(int argc, char *argv[]) {	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);	glutInitWindowSize(screenWidth, screenHeight);	glutInitWindowPosition(0,0);	glutCreateWindow("GAME");	myInit();	glutDisplayFunc(myDisplay);	glutIdleFunc(myDisplay);	glutKeyboardFunc(myKeyboard);	glutKeyboardUpFunc(myKeyup);	glutTimerFunc(1000, timer, 0);	glutMainLoop();	return 0;	}

This is my main.cpp.
And here is the member function of my "ship" class that actually draws it:
void Vessel::drawtexture(void) {	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);	glTexImage2D(GL_TEXTURE_2D, 0, 3, BitmapInfo->bmiHeader.biWidth, BitmapInfo->bmiHeader.biHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BitmapBits);	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);    glEnable(GL_TEXTURE_2D);	glShadeModel(GL_FLAT);	glMatrixMode(GL_MODELVIEW);	glPushMatrix();	glTranslatef(x, y, 0);	glRotatef(alignment*(360/32), 0, 0, 1);	glTranslatef(-64/2, -64/2, 0);	glBegin(GL_QUADS);	glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);	glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 64.0);	glTexCoord2f(1.0, 1.0); glVertex2f(64.0, 64.0);	glTexCoord2f(1.0, 0.0); glVertex2f(64.0, 0.0);	glEnd();	glPopMatrix();	}

Anything wrong with these?

##### Share on other sites
You need to use extensions to turn on V-sync. If you haven't had experience with them before, they are a pain to learn. I have scoured the net for the simplest V-sync code, and found it. If you don't plan on using any advanced extensions in your game, I can give you the simple code needed to turn it on. On the other hand, you could go read up on extensions and be prepared for them the next time you need to use one.

##### Share on other sites
Thank you, Scott. At least something starts to make sense now. I would be very grateful if you give me the link to it or just send it on thamior at mail dot ru. Thank you.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634124
• Total Posts
3015659
×