OpenGL API Specifications

Documents and Learning ResourcesSupport Libraries and FrameworksFunction Libraries and GeneratorsThis list contains some basic resources for getting started with, and developing for, OpenGL 3.0 and onwards. Contact your forum moderator if you want to contribute to the list or have any comments.-
##### Interactive Music / Sound Designer | Audio Programming

Raúl Ibarra Aranda -
##### SFX Designer/Composer/Dialogue/Audio Implementation

Matthewdeargameaudio -
##### Game Development Studio for Hire

JanJohansson -
##### Elastic Music - Experienced Composer

Elastic Music

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Started by storm33229, Aug 08 2011 06:37 PM

4: Adsense

**Guest**, the last post of this topic is over **60 days old** and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

- You cannot reply to this topic

3 replies to this topic

Posted 08 August 2011 - 06:37 PM

I am using OpenGL and C to create a 2D rendering engine. I am learning about VBOs and how to use them for non-immediate mode rendering. I have been reading from: http://www.opengl.org/wiki/Vertex_Buffer_Object

The tutorial suggests the following:

struct MyVertex

{

float x, y, z; //Vertex

float nx, ny, nz; //Normal

float s0, t0; //Texcoord0

float s1, t1; //Texcoord1

float s2, t2; //Texcoord2

float padding[4];

};

I do not need the Normal values, and I am unsure how or why there are three texture coordinates for a single vertex.

I think all I should need is Vertex (XYZ), and one Texcoord (s0, t0 <-- still do not know what those mean).

The tutorial suggests the following:

struct MyVertex

{

float x, y, z; //Vertex

float nx, ny, nz; //Normal

float s0, t0; //Texcoord0

float s1, t1; //Texcoord1

float s2, t2; //Texcoord2

float padding[4];

};

I do not need the Normal values, and I am unsure how or why there are three texture coordinates for a single vertex.

I think all I should need is Vertex (XYZ), and one Texcoord (s0, t0 <-- still do not know what those mean).

Posted 08 August 2011 - 07:26 PM

This is my vertex structure, also for 2D:

That makes a size of 36 bytes per Vertex.

That leads to the following Vertex Attribute Set:

Shader-Layout:

So yes, you need only 1 set of texture-coordinates per Vertex. Don't know why they use it like this in that tutorial.

Why they are called S and T is something I did not figure out after reading 3 Books and an unknown amount of websites regarding the topic .

I just take it as a given naming .

Good Tutorial:

Learning Modern 3D Graphics Programming Through OpenGL

struct NLVertexData { /// \brief Constructor NLVertexData() : x(0), y(0), z(0), r(1), g(1), b(1), a(1), s(0), t(0) {} /// \brief X f32 x; /// \brief Y f32 y; /// \brief Z f32 z; /// \brief Red f32 r; /// \brief Green f32 g; /// \brief Blue f32 b; /// \brief Alpha f32 a; /// \brief s f32 s; /// \brief t f32 t; };

That makes a size of 36 bytes per Vertex.

That leads to the following Vertex Attribute Set:

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(NLVertexData), 0); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(NLVertexData), (void*)(3*sizeof(float))); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(NLVertexData), (void*)(7*sizeof(float)));

Shader-Layout:

layout(location = 0) in vec3 Vertex; layout(location = 1) in vec4 Color; layout(location = 2) in vec2 TextureCoord;

So yes, you need only 1 set of texture-coordinates per Vertex. Don't know why they use it like this in that tutorial.

Why they are called S and T is something I did not figure out after reading 3 Books and an unknown amount of websites regarding the topic .

I just take it as a given naming .

Good Tutorial:

Learning Modern 3D Graphics Programming Through OpenGL

If you say "pls", because it is shorter than "please", I will say "no", because it is shorter than "yes"

http://nightlight2d.de/

http://nightlight2d.de/

Posted 08 August 2011 - 07:34 PM

I am using OpenGL and C to create a 2D rendering engine. I am learning about VBOs and how to use them for non-immediate mode rendering. I have been reading from: http://www.opengl.or...x_Buffer_Object

The tutorial suggests the following:

struct MyVertex

{

float x, y, z; //Vertex

float nx, ny, nz; //Normal

float s0, t0; //Texcoord0

float s1, t1; //Texcoord1

float s2, t2; //Texcoord2

float padding[4];

};

I do not need the Normal values, and I am unsure how or why there are three texture coordinates for a single vertex.

I think all I should need is Vertex (XYZ), and one Texcoord (s0, t0 <-- still do not know what those mean).

Then make your structure like this

struct MyVertex

{

float x, y, z; //Vertex

float s0, t0; //Texcoord0

};

or if you want it to by 32 bytes

struct MyVertex

{

float x, y, z; //Vertex

float s0, t0; //Texcoord0

float padding[3];

};

s0 and t0 are texcoords (XY). You can call it whatever you want such as

struct MyVertex

{

float fatso_x, fatso_y, fatso_z; //Vertex

float nipples_x, nipples_y; //Texcoord0

float padding[3];

};

Sig: http://glhlib.sourceforge.net

an open source GLU replacement library. Much more modern than GLU.

float matrix[16], inverse_matrix[16];

glhLoadIdentityf2(matrix);

glhTranslatef2(matrix, 0.0, 0.0, 5.0);

glhRotateAboutXf2(matrix, angleInRadians);

glhScalef2(matrix, 1.0, 1.0, -1.0);

glhQuickInvertMatrixf2(matrix, inverse_matrix);

glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);

glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

an open source GLU replacement library. Much more modern than GLU.

float matrix[16], inverse_matrix[16];

glhLoadIdentityf2(matrix);

glhTranslatef2(matrix, 0.0, 0.0, 5.0);

glhRotateAboutXf2(matrix, angleInRadians);

glhScalef2(matrix, 1.0, 1.0, -1.0);

glhQuickInvertMatrixf2(matrix, inverse_matrix);

glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);

glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posted 08 August 2011 - 08:18 PM

Thank you both for those examples. I about choked on what I was drinking when I read fatso and nipples.

**Guest**, the last post of this topic is over **60 days old** and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

Reply to quoted posts Clear

Copyright © 1999-2017 GameDev.net, LLC

GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.