Author Topic: [C#] Background texture problems.  (Read 4356 times)

0 Members and 1 Guest are viewing this topic.

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
[C#] Background texture problems.
« 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:
Code: [Select]
       
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:

Code: [Select]
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
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: [C#] Background texture problems.
« Reply #1 on: December 05, 2009 »
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.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Re: [C#] Background texture problems.
« Reply #2 on: December 05, 2009 »
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
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C#] Background texture problems.
« Reply #3 on: December 05, 2009 »
How many times a second are you trying to draw your display?

Jim
Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Re: [C#] Background texture problems.
« Reply #4 on: December 05, 2009 »
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
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: [C#] Background texture problems.
« Reply #5 on: December 06, 2009 »
K+ for letting us know
Shockwave ^ Codigos
Challenge Trophies Won: