Texture loading problem in OpenGL

General FreeBASIC programming questions.
Post Reply
Shocking
Posts: 79
Joined: Nov 14, 2005 19:56

Texture loading problem in OpenGL

Post by Shocking »

I finally gotten the hang of loading the textures in OpenGL only one problem.

When loading the texture and successfully displaying it, it also effects the main color pallete as well.

Where if you do "glcolor3f 1,1,1", all the drawings won't be white instead, they will come up a different color.

I have lost a lot of sleep trying to solve this problem, and would like to know how this could be solved.

Currently using:

createtex.bi

Freebasic version .17 Dec 26 Build

p.s. I tried searching for similar problems like this on the forums but not much results I say.
L_O_J
Posts: 181
Joined: Aug 20, 2005 9:05

Post by L_O_J »

Hmm
1st, post some code pls, we (well me) are not wizard or a mind reader.
2nd, what bit depth do you use ? the word pallete confuses me :p, since well using GL in palletezied environment is a bit odd (ie I never found a program (game or non game) that uses it that way).
Maz
Posts: 32
Joined: Jun 16, 2005 20:44

Re: Texture loading problem in OpenGL

Post by Maz »

Shocking wrote:I finally gotten the hang of loading the textures in OpenGL only one problem.

When loading the texture and successfully displaying it, it also effects the main color pallete as well.

Where if you do "glcolor3f 1,1,1", all the drawings won't be white instead, they will come up a different color.

I have lost a lot of sleep trying to solve this problem, and would like to know how this could be solved.

Currently using:

createtex.bi

Freebasic version .17 Dec 26 Build

p.s. I tried searching for similar problems like this on the forums but not much results I say.
glcolor acts like a tint applier when rendering with textures. What you need to do is set glcolor 1,1,1 before rendering your texture to have it displayed as you would see the image regularly, any other values and it will alter the brightness and hues of the textures..

Now, if you try to draw stuff after using textures you will end up with either coloring results.. i could be wrong but if you dont specify tex coords as if it is to be a flat shaded polygon i think it takes the color of the first pixel in the corner of currently bound texture, and just renders the poly with it.

Which in turn leaves strange colors appearing when you attempt to draw single colour bits and bobs. This is the only kinda thing I can imagine is happening. As i've done the same and been confused myself.

If this is the case, never forget to glDisable GL_TEXTURE_2D before you attempt to render any non textured pieces and of course reenable it before you want to texture again.
Shocking
Posts: 79
Joined: Nov 14, 2005 19:56

Post by Shocking »

Here is the source code for my program.

Uses multiple files, and yes I ment to put the text over the texture.

And requires "createtex.bi" as well.

What I am trying to do is, not have a bitmap file effect the rest of the color pallete system, and load multiple different textures at the same time.

I tried binding other textures with seperate glbegin and glend loops but that doesn't work out really well.

I apologize for some unused parts that are in the source as well and don't have the time to take it out and resubmit it.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

What version of fb are you using? .17? .17 CVS?

If you are using the CVS version, then you are commiting a major no-no. NEVER try to auto-calculate the size of the buffer you need in >= 8-bpp modes. You don't know the internal pitch formula. Further, you have the wrong header size. Simply put, let gfxlib do it's job and you may have less problems.

Code: Select all

dim mbuffer(256*256*4+4) as ubyte       '' Size = Width x Height x 4 bytes per pixel + 4 bytes for heade
^ WRONG! ^

Buffer overflow! haha, you lose!

If you are using GL, then you should really brush up on the major internal changes to the compiler and learn what to do and most definitely what not to do.

Read the changelog.txt file, it's important.


Also, there are a few 2d GL-backend libs which are simple to use. If you want one coded in fb, look at myGL or at this one: http://ecowles.dyndns.org/stuff/alpha.rar
Shocking
Posts: 79
Joined: Nov 14, 2005 19:56

Post by Shocking »

Well I'm more of an artists than an advanced programmer that knows everything about memory pointers and buffers

The code you posted was the BMP loading codes that were ripped from those NeHe GL tutorials because I just wanted to program a 2D shooter game.

As for taking a look at the two things you suggested, the libs look like they havent been updated while there are no examples provided with them.

Or just not looking for things right.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

Well, those NeHe tutorials are not the best translations.

You should always use the methods provided to create and destroy library dependant structures. The graphics header for .17 is now 32 bytes and not 4 bytes which is what is most likely causing your program to fail. You should instead use FB.IMAGE Ptr coupled with ImageCreate/ImageDestroy and let the library handle the creation of the graphics buffer.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

hello there

Post by thesanman112 »

take a look in tips and tricks....I post all kinds of neat gizmo's to play with..also check projects, most people that post projects post source too...
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

artists wanted...

Post by thesanman112 »

can you make some cool bitmaps to use a textures? I need some...I have read your responces to suggestions from maz...maybe its something really simple...ya know?....some say you should only use one set of glbegin' and glend, meaning that you can only use one texture...this in completely false...I have been able to jump out of main draw routine and draw gl objects as well as mutiple textures, it took some time but i finally got it, stick with it ...good luck
Dr_D
Posts: 2451
Joined: May 27, 2005 4:59
Contact:

Re: artists wanted...

Post by Dr_D »

thesanman112 wrote:some say you should only use one set of glbegin' and glend, meaning that you can only use one texture...this in completely false...I have been able to jump out of main draw routine and draw gl objects as well as mutiple textures, it took some time but i finally got it, stick with it ...good luck

That isn't false. You should download and read some of the OpenGL books. Texture binding is not allowed within a GlBegin...GlEnd block. Sure, you can do it, but you can also access an out of bounds pointer array... sometimes it even works! FreeBASIC allows you to muck things up, as does OpenGL. The correct way is to...

Code: Select all

do
    Bind texture
        glbegin
            draw polygons
        glend
loop
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

yeper's

Post by thesanman112 »

yes I know.....he want to do it within the glulookat scope im asuming, but not using glulookat it must be exactly the same, not sure....funny things happen from time to time, heheh you got that right....i believe the key to the question is within the same array maybe, I dont get enough time to hack all the code that gets posted but....myself I have had alot of trouble when using a gl_texture from a bitmap... like using someone else's bitmap to gl texture routine.. I had sucess with freebio routines. However I have tried to use it without the glulookat like gl mode without sdl and could not get it to work.....so the problem that shocking is having may be that he is using loaded bitmaps.....WHERES SOME CODE!!!!!!hehehe
Post Reply