Reputation: 3417
Here's my code
vertex shader
#version 430
in vec3 position;
uniform mat4 MVP;
void main()
{
gl_Position = MVP * vec4(position, 1.0);
}
fragment shader
#version 430
out vec4 outputColor;
uniform sampler2D tex;
void main()
{
outputColor = texture(tex, gl_PointCoord);
}
init
void init()
{
glPointSize(20.0f);
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
bmp.Open("C:\\users\\alon\\desktop\\star.bmp");
bmp.ReadPixels();
unsigned char *pixels = new unsigned char[bmp.NeededBufferSize()];
bmp.AssignPixels(pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmp.GetWidth(), bmp.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
delete[] pixels;
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GLuint VaoId;
glGenVertexArrays(1, &VaoId);
glBindVertexArray(VaoId);
position_index = glGetAttribLocation(program, "position");
MVP_location = glGetUniformLocation(program, "MVP");
// x y z s t
GLfloat vertices[] = {-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
-0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f};
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(position_index, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
render
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableVertexAttribArray(position_index);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
float c;
if(bTime)
c = (float)std::clock() * 2.0f / CLOCKS_PER_SEC;
else
c = 0.0f;
glm::mat4 modelview = glm::rotate(-c * 50.0f, glm::vec3(0.0f, 1.0f, 0.0f));
modelview = glm::translate(glm::vec3(0.0f + fTranslateX, 0.0f, -1.75f + fTranslateZ)) * modelview;
glm::mat4 projection = glm::perspective(60.0f, 16.0f/9.0f, 0.10f, 100.0f); //perspective
glm::mat4 MVP = projection * modelview;
glUniformMatrix4fv(MVP_location, 1, GL_FALSE, &MVP[0][0]);
glDrawArrays(GL_POINTS, 0, 6);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableVertexAttribArray(position_index);
glutSwapBuffers();
if(glGetError() != GL_NO_ERROR)
exit(1);
}
Is there anything I'm doing wrong?
Upvotes: 0
Views: 2143
Reputation: 43329
In compatbility profiles (or any version of GL before 3.1), the behavior you want only occurs when GL_POINT_SPRITE
is enabled. In a core profile, that state was removed, and gl_PointCoord
always behaves as if GL_POINT_SPRITE
were enabled.
To fix your problem, you must call glEnable (GL_POINT_SPRITE)
.
Upvotes: 2