OpenGL with vertex arrays

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

OpenGL with vertex arrays

Post by N64vSNES »

EDIT:
See newest post...
Last edited by N64vSNES on Wed Aug 31, 2011 8:36 am, edited 2 times in total.
User avatar
Nokurn
Chaos Rift Regular
Chaos Rift Regular
Posts: 164
Joined: Mon Jan 31, 2011 12:08 pm
Favorite Gaming Platforms: PC, SNES, Dreamcast, PS2, N64
Programming Language of Choice: Proper C++
Location: Southern California
Contact:

Re: OpenGL texture question

Post by Nokurn »

N64vSNES wrote:I can't seem to find an answer for this so hopefully you guys could help.

Suppose I have a 32x32 texture and a 64x64 quad. Now if I render this then the texture gets "stretched" as you would imagine because you've specified the texture coords where the vertices are.

I'm fairly sure that using GL_REPEAT would do this IF I go past 1.0 with the texture coords however this isn't much using part of a texture atlas.

Any advice?

Thanks.
I am not quite sure what you are asking here. There is no question, and it looks like there's supposed to be a sentence between the second and third. If you could rephrase, someone might be able to provide some insight.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OpenGL texture question

Post by Falco Girgis »

Krolgar wrote:
N64vSNES wrote:I can't seem to find an answer for this so hopefully you guys could help.

Suppose I have a 32x32 texture and a 64x64 quad. Now if I render this then the texture gets "stretched" as you would imagine because you've specified the texture coords where the vertices are.

I'm fairly sure that using GL_REPEAT would do this IF I go past 1.0 with the texture coords however this isn't much using part of a texture atlas.

Any advice?

Thanks.
I am not quite sure what you are asking here. There is no question, and it looks like there's supposed to be a sentence between the second and third. If you could rephrase, someone might be able to provide some insight.
That's exactly what I was going to say.

You never asked us a question.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL texture question

Post by N64vSNES »

Yes I see where I went wrong there :oops:
I'll start from the beginning :lol:

Suppose this is my texture:
Image

I want to use this texture on a quad like this:
Image

I could break the quad into 4 different quads but then I'm losing performance.


Short and simple as possible :)
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL texture question

Post by qpHalcy0n »

This can not be done as you describe within the fixed function. Sorry.

The texture or the geometry must be split or you must write the functionality into a shader program.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL texture question

Post by N64vSNES »

qpHalcy0n wrote:This can not be done as you describe within the fixed function. Sorry.

The texture or the geometry must be split or you must write the functionality into a shader program.
Well this is going to cause problems :lol:

Thanks for the help though.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OpenGL texture question

Post by Falco Girgis »

N64vSNES wrote:
qpHalcy0n wrote:This can not be done as you describe within the fixed function. Sorry.

The texture or the geometry must be split or you must write the functionality into a shader program.
Well this is going to cause problems :lol:

Thanks for the help though.
I'm guessing you're just trying to optimize some shit? ...you could always pick up shaders. :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL texture question

Post by N64vSNES »

GyroVorbis wrote:
N64vSNES wrote:
qpHalcy0n wrote:This can not be done as you describe within the fixed function. Sorry.

The texture or the geometry must be split or you must write the functionality into a shader program.
Well this is going to cause problems :lol:

Thanks for the help though.
I'm guessing you're just trying to optimize some shit? ...you could always pick up shaders. :)
Yep. The only alternative would be dropping the whole texture atlas buissness but then I doubt I'd gain much performance having to switch textures. in fact, I might even make it slower that way :lol:

I'll look into shaders...Probably won't end pretty xD
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL texture question

Post by qpHalcy0n »

...or you could just split up the geometry. You know that the vertex transformation pipeline is extremely optimized and that you should have no problem pushing dozens of thousands and thousands and thousands of polys through it.
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL texture question

Post by N64vSNES »

qpHalcy0n wrote:...or you could just split up the geometry. You know that the vertex transformation pipeline is extremely optimized and that you should have no problem pushing dozens of thousands and thousands and thousands of polys through it.
Vertex transformation pipeline, optimized. I was about to say the same thing! :shock:
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: OpenGL with vertex arrays

Post by N64vSNES »

I decided to edit this topic since I didn't want to spam the forum with tedious questions like this.

So I finally took qpHalcy0n's advice...Or reality slap and actually implemented a vertex array for Crafter. (Yes I was stupid enough to render the entire map with the immediate pipeline)

Now it works and perfectly with a much higher poly count as expected. But I did hit a problem with the textures.

Now here is how I render the map:

Code: Select all

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,t_BlockSet.GetTex());
		glColor3f(1,1,1);
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);

		glVertexPointer(3, GL_FLOAT, 0, &Verts[0].x);
		glTexCoordPointer(2,GL_FLOAT, 0, &TexChoords[0].x);

		glDrawArrays(GL_QUADS,0,i_FacesDrawn * 4);

		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_VERTEX_ARRAY);
The map renders correctly, but the textures are pretty screwed:
Image

So, help? :lol:

The texture coords are definitely correct, there are a equal number of vertices as there are texture coords, all the basic stuff seems fine.

Am I missing something obvious?
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: OpenGL with vertex arrays

Post by Ginto8 »

It looks like some of the edges are slanted, so you might not be feeding some vertices into the pipeline that you should be, or you're feeding them in incorrectly.
The only thing that could make those kinds of texture errors, to my knowledge, is wrong texture coordinates :|
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
TheBuzzSaw
Chaos Rift Junior
Chaos Rift Junior
Posts: 310
Joined: Wed Dec 02, 2009 3:55 pm
Current Project: Paroxysm
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: OpenGL with vertex arrays

Post by TheBuzzSaw »

Did you switch to indexed rendering? Or are you still repeating vertices?
Post Reply