백승호
백승호

Reputation: 15

opengl - how to chage vertex information

I want to increase or decrease the size of the triangle.

and my verte.glsl

#version 330
    
layout (location = 0) in vec3 in_Position; //--- 위치 변수: attribute position 0

uniform vec3 move;

void main(void) 
{
    gl_Position = vec4(in_Position.x + move.x, in_Position.y + move.y, in_Position.z + move.z, 1.0);
}

The move variable is a uniform variable that can be moved through a timer in the main program. But I don't know how to change the size of this triangle. I think, I want to pass a new value to the in_position variable in the cpp file, but I don't know.

Upvotes: 1

Views: 66

Answers (1)

Rabbid76
Rabbid76

Reputation: 211229

I think, I want to pass a new value to the in_position variable

No. Vertices should be transformed on the GPU in the vertex shader, as you did with move.


You can scale the coordinate. Add uniform vec3 scale to your shader code and multiply the in_position by scale. Initialize scale with (1, 1, 1). Increase the scalars to make the triangle larger.

#version 330

layout (location = 0) in vec3 in_Position;

uniform vec3 move;
uniform vec3 scale;

void main(void) 
{
    gl_Position = vec4(in_Position.xyz * scale + move, 1.0);
}

However, the usual way is not to use a transformation matrix:

#version 330

layout (location = 0) in vec3 in_Position; 

uniform mat4 model_transform;

void main(void) 
{
    gl_Position = model_transform * vec4(in_Position.xyz, 1.0);
}

You can encode the scale, rotation and translation in 1 transformation matrix.

Upvotes: 1

Related Questions