Draw Part Of OpenGL Texture?

Draw Part Of OpenGL Texture?

Hi,

I’ve Google’d for hours, but have not seen how to do this.
How do I draw only a small part of an OpenGL texture?
I’m using SDL 1.2 + OpenGL.

Thanks!------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

Are you drawing with OpenGL, or are you using an OpenGL backend for
regular SDL functions?

If using pure OpenGL, you can use the texture co-ordinates to change
which part is rendered.On 17 June 2010 18:55, JeZ-l-Lee wrote:

Draw Part Of OpenGL Texture?

Hi,

I’ve Google’d for hours, but have not seen how to do this.
How do I draw only a small part of an OpenGL texture?
I’m using SDL 1.2 + OpenGL.

Thanks!

glTexCoord2f/glTexCoord2i

basically, glTexCoord2f uses 1.0 to represent the highest value side (right and bottom) and 0.0 to represent the lowest value side (left and top); or maybe I have it backwards 'cause I haven’t touched GL in too long. So if you want to draw, say, the top-left 32x32 pixels of a 64x64 image…
glTexCoord2f(1.0, 0.5); // top-right
glTexCoord2f(1.0, 1.0); // bottom-right
glTexCoord2f(0.5, 1.0); // bottom-left
glTexCoord2f(0.5, 0.5); // top-left

or something like that. Don’t forget to put the vertex coords there too.------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

Not sure I understand the question fully. If you’re drawing the
texture by mapping it onto OpenGL polygons, you can change the texture
coordinates. Coordinates spanning (0, 0) to (1, 1) will show your
whole texture. But if you just have coordinates spanning a smaller
range like (0, 0) to (0.5, 0.5) you’ll only see part of the texture.–
Terry Welsh
mogumbo ‘at’ gmail.com
www.reallyslick.com

Message: 3
Date: Thu, 17 Jun 2010 10:55:19 -0700
From: “JeZ-l-Lee”
To: sdl at lists.libsdl.org
Subject: [SDL] Draw Part Of OpenGL Texture?
Message-ID: <1276797318.m2f.24411 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Draw Part Of OpenGL Texture?

Hi,

I’ve Google’d for hours, but have not seen how to do this.
How do I draw only a small part of an OpenGL texture?
I’m using SDL 1.2 + OpenGL.

Thanks!


JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

Is that how sprite sheets are usually delt with? I saw this thread and
immediately thought “I can probably do sprite sheets like that” (I’m
currently updating my project to use OpenGL).On Jun 17, 2010, at 4:26 PM, Terry Welsh wrote:

Not sure I understand the question fully. If you’re drawing the
texture by mapping it onto OpenGL polygons, you can change the texture
coordinates. Coordinates spanning (0, 0) to (1, 1) will show your
whole texture. But if you just have coordinates spanning a smaller
range like (0, 0) to (0.5, 0.5) you’ll only see part of the texture.

Terry Welsh
mogumbo ‘at’ gmail.com
www.reallyslick.com

Message: 3
Date: Thu, 17 Jun 2010 10:55:19 -0700
From: “JeZ-l-Lee”
To: sdl at lists.libsdl.org
Subject: [SDL] Draw Part Of OpenGL Texture?
Message-ID: <1276797318.m2f.24411 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Draw Part Of OpenGL Texture?

Hi,

I’ve Google’d for hours, but have not seen how to do this.
How do I draw only a small part of an OpenGL texture?
I’m using SDL 1.2 + OpenGL.

Thanks!


JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

That’s certainly how you would do sprites in OpenGL or other 3D APIs.
For example, I’m using sheets of smaller textures like this for
particles and lens flare textures, which helps to minimize expensive
OpenGL texture state changes. I think sprite sheets are way more
common in 2D apps, though.–
Terry Welsh
mogumbo ‘at’ gmail.com
www.reallyslick.com

Message: 7
Date: Thu, 17 Jun 2010 19:28:01 -0400
From: Saturn Almighty <6.saturn.6 at gmail.com>
To: SDL Development List
Cc: “sdl at lists.libsdl.org
Subject: Re: [SDL] Draw Part Of OpenGL Texture?
Message-ID: <724F57C0-B036-42B8-9EA8-0F8CC7EDD834 at gmail.com>
Content-Type: text/plain; ? ? ? charset=us-ascii; ? ? ? format=flowed; ?delsp=yes

Is that how sprite sheets are usually delt with? I saw this thread and
immediately thought “I can probably do sprite sheets like that” (I’m
currently updating my project to use OpenGL).

On Jun 17, 2010, at 4:26 PM, Terry Welsh <@Terry_Welsh> wrote:

Not sure I understand the question fully. ?If you’re drawing the
texture by mapping it onto OpenGL polygons, you can change the texture
coordinates. ?Coordinates spanning (0, 0) to (1, 1) will show your
whole texture. ?But if you just have coordinates spanning a smaller
range like (0, 0) to (0.5, 0.5) you’ll only see part of the texture.

Terry Welsh
mogumbo ‘at’ gmail.com
www.reallyslick.com

Message: 3
Date: Thu, 17 Jun 2010 10:55:19 -0700
From: “JeZ-l-Lee”
To: sdl at lists.libsdl.org
Subject: [SDL] Draw Part Of OpenGL Texture?
Message-ID: <1276797318.m2f.24411 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Draw Part Of OpenGL Texture?

Hi,

I’ve Google’d for hours, but have not seen how to do this.
How do I draw only a small part of an OpenGL texture?
I’m using SDL 1.2 + OpenGL.

Thanks!


JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com