繁体   English   中英

在使用顶点/片段着色器时,使用 glRotatef、glPushMatrix... 问题

[英]While using Vertex/Fragment Shader, using glRotatef, glPushMatrix... Problem

我编写了顶点着色器、片段着色器。 我想使用 glPushMatrix/glPopMatrix、glRotatef/glTranslatef... 但是,它不起作用。

我用坐标、颜色、索引制作“类”。 我试着用 vao、vbo、ebo 画画。

*renderScene 函数

void renderScene_sub1(void){
glutSetWindow(subwindow1);

//Clear all pixels
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();


//Let's draw something here

//define the size of point and draw a point.
GLint viewmatLoc = glGetUniformLocation(programID, "viewmat");
glUniformMatrix4fv(viewmatLoc, 1, GL_FALSE, &viewmat[0][0]);



sub1_window.bind_vao();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glTranslatef(-0.5, -0.5, 0.0);
glDrawArrays(GL_TRIANGLES, 1, 3 );

//glDrawElements(GL_TRIANGLES, sub1_window.get_indices_size(), GL_UNSIGNED_BYTE, 0);

glPopMatrix();


//Double buffer
glutSwapBuffers();}

*初始化函数

void init_sub1(){
//initilize the glew and check the errors.
GLenum res = glewInit();
if (res != GLEW_OK)
{
    fprintf(stderr, "Error: '%s' \n", glewGetErrorString(res));
}

//select the background color
glClearColor(0.8, 0.8, 0.8, 1.0);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);



//input vertex
sub1_window.push_vertices(0.5, 0, 0);
sub1_window.push_vcolor(1, 1, 0);

sub1_window.push_vertices(0.5, 0.5, 0);
sub1_window.push_vcolor(0, 1, 1);

sub1_window.push_vertices(0, 0.5, 0.5);
sub1_window.push_vcolor(1, 0, 1);

sub1_window.push_vertices(0, 0, 0.5);
sub1_window.push_vcolor(0, 0, 1);

sub1_window.push_indices(0, 1, 2);
sub1_window.push_indices(2, 3, 0);

programID = LoadShaders("VertexShader.txt", "FragmentShader.txt");

glUseProgram(programID);

sub1_window.gen_vao();
sub1_window.bind_vao();


//vbo
sub1_window.gen_vbo_buffer(2);

sub1_window.bind_vbo_buffer("vertices");
sub1_window.buffer_vbo_data("vertices");

GLint vtxPosition = glGetAttribLocation(programID, "vtxPosition");
glVertexAttribPointer(vtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, (GLvoid*)(0));
glEnableVertexAttribArray(vtxPosition);


sub1_window.bind_vbo_buffer("vcolor");
sub1_window.buffer_vbo_data("vcolor");

GLint vColor = glGetAttribLocation(programID, "vColor");
glVertexAttribPointer(vColor, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, (GLvoid*)(0));
glEnableVertexAttribArray(vColor);

//ebo
sub1_window.gen_ebo();

sub1_window.bind_ebo_buffer();
sub1_window.buffer_ebo_data();

viewmat = glm::rotate(tiltRad * TO_RADIAN, glm::vec3(1.0f, 0, 0)) * glm::rotate(panRad * TO_RADIAN, glm::vec3(0.0f, 1.0f, 0));}

我想使用 glPushMatrix/glPopMatrix、glRotatef/glTranslatef...

为什么?

但是,它不起作用。

是的。

我在谷歌搜索,并运行示例。 我不知道为什么它不适用。

因为这些函数是旧的、过时的、已弃用的固定函数管道的一部分。 除非您使用的是旧版 OpenGL(或兼容性配置文件),否则这些功能将不再起作用 所以不要使用它们

如果您正在学习的材料仍在使用它们,或者旧版 OpenGL 的任何其他部分,请停止使用这些材料。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM