Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: James_wright_1990 on December 05, 2009
-
Hi I just added a background texture to the game I was working on and its taken a massive performance hit. It's now running at about half the speed it was before and I can't figure out why. The loading code looks like this:
private void LoadGLTextures()
{
Gl.glEnable(Gl.GL_TEXTURE_2D);
Bitmap image = new Bitmap("Background.bmp");
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
System.Drawing.Imaging.BitmapData bitmapdata;
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
bitmapdata = image.LockBits(rect,
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[0]);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, (int)Gl.GL_RGB8, image.Width,
image.Height, 0, Gl.GL_BGR_EXT,
Gl.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER,
Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER,
Gl.GL_LINEAR);
image.UnlockBits(bitmapdata);
image.Dispose();
Gl.glDisable(Gl.GL_TEXTURE_2D);
}
and the drawing code looks like this:
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glBegin(Gl.GL_QUADS);
//Front Face
Gl.glColor3d(0.7, 0.5, 0.5);
Gl.glTexCoord2f(0.0f, 0.0f);
Gl.glVertex2d(0, 0);//BotLft Of The Texture and Quad
Gl.glTexCoord2f(1.0f, 0.0f);
Gl.glVertex2d(screenWidth, 0);//BotRt Of The Texture and Quad
Gl.glTexCoord2f(1.0f, 1.0f);
Gl.glVertex2d(screenWidth, screenHieght); //Top Right Of The Texture and Quad
Gl.glTexCoord2f(0.0f, 1.0f);
Gl.glVertex2d(0, screenHieght); //Top Left Of The Texture and Quad
Gl.glEnd();
Gl.glDisable(Gl.GL_TEXTURE_2D);
Can anybody help.
James
-
What size in pixels is the background texture you are using James?
are they non-power of two textures? Surprisingly some cards really struggly if the widths + heights aren't powers of two.
-
Hi I had got it in the wrong size but when i changed it there was still a big drop in performance (not as big but still very slow). I have a freinds who using the same technique to load and display a textures and its works fine for him, the only difference between my program and his as far as i can tell is that i am using FreeGlut to open and manage the window and he is using windows forms and so the only thing i can think of is that it is something to do with FreeGlut.
Thanks for the reply
James
-
How many times a second are you trying to draw your display?
Jim
-
Hi
It turns out that freeglut was calling display far to often so Ive limited it and now it works fine cheers for the help I was getting nowhere on my own
anywho all is good now.
James
-
K+ for letting us know