Jump to content
  • Advertisement
Sign in to follow this  
storm33229

OpenGL Custom Vertex structure

This topic is 2537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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).

Share this post


Link to post
Share on other sites
Advertisement
This is my vertex structure, also for 2D:



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 :P.
I just take it as a given naming :lol:.

Good Tutorial:

Learning Modern 3D Graphics Programming Through OpenGL

Share this post


Link to post
Share on other sites

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];
};

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!