Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

Lets say i have an array of floats:

C#
float[] points = {1.0, 0.0, 0.5,
1.0, 1.0,
1.0, 1.0, 1.0};


This is one point on ex a triangle, where the first 3 floats are coordinates, the 2 next texture coordinates, and the last 3 normal coordinates.

How do i fast draw this in OpenGL using GLSL(If needed)?
Posted
Comments
lukeer 19-Nov-12 4:28am    
How would you do it without that array?
Liam S. Crouch 19-Nov-12 4:52am    
glNormal3f()glTexCoord() glVertex3f();

1 solution

I've never done anything in OpenGL. But referring to MSDN[^], I suggest
C#
float[] points = {
    1.0F, 0.0F, 0.5F,
    1.0F, 1.0F,
    1.0F, 1.0F, 1.0F
};

glNormal3f(points[0], points[1], points[2]);
glTexCoord2f(points[3], points[4]);
glVertex3f(points[5], points[6], points[7]);

points is an array. You can access its elements using the correct index in square brackets. Be careful not to use a non-existent index for it will result in an exception.

Have you considered to use a custom object with more descriptive naming for the floats? (I don't know the performance penalty, though). It could read something like that:
C#
// Definition of your custom data holder class
class TriangleCoordinages
{
    public float NormalX, NormalY, NormalZ;
    public float TextureX, TextureY;
    public float LocationX, LocationY, LocationZ;

    public TriangleCoordinates(
        float normalX, float normalY, float normalZ,
        float textureX, float textureY,
        float locationX, float locationY, float locationZ
    ){
        NormalX = normalX;
        NormalY = normalY;
        NormalZ = normalZ;
        TextureX = textureX;
        TextureY = textureY;
        LocationX = locationX;
        LocationY = locationY;
        LocationZ = locationZ;
    }
}

// Instantiation of a data holder object
TriangleCoordinates triangle = new TriangleCoordinates(
    1.0F, 0.0F, 0.5F,
    1.0F, 1.0F,
    1.0F, 1.0F, 1.0F
);

// Using data within the data holder object
glNormal3f(triangle.NormalX, triangle.NormalY, triangle.NormalZ);
glTexCoord2f(triangle.TextureX, triangle.TextureY);
glVertex3f(triangle.LocationX, triangle.LocationY, triangle.LocationZ);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900