使用键盘输入的OpenGL转换不工作
OpenGL transformation with keyboard input not working
我正试图将转换应用于我的绘图的特定部分,只有在按下键时才会生效。我使用glPushMatrix()然后进行转换,然后是glPopMatrix()当我按下我的键时发生的是,转换只完成一次,然后无论我再按多少次键都没有发生任何变化。
下面是我的代码片段:
void drawShapes(){
glClear(GL_COLOR_BUFFER_BIT);
//setting my variables
glPushMatrix();
if (translateFlag) //this is set to true in the keyboard function
{
x += 10;
glTranslated(x, 0, 0);
translateFlag = false;
}
drawCircle();
glPopMatrix();
//more drawings
}
当我删除pushMatrix和popMatrix时,它可以工作,但它将转换应用于我所有的形状,这不是我想要的。如有任何帮助,我将不胜感激。
(更新)我试着在其他4台电脑上运行我的代码(一台macbook Air,一台macbook Pro——和我的一模一样——还有2台imac和),它甚至不能在任何一台电脑上运行,这是否意味着问题出在我自己的macbook上?!我还复制了在macbook air上运行得很好的代码,旋转部件和所有东西,当我在我的电脑上运行它时,我得到了和我自己的代码一样令人失望的结果。
这是我的代码31JL的heypasteit代码
可能出现的问题:
void drawShapes(){
glClear(GL_COLOR_BUFFER_BIT);
//setting my variables
// maybe you have forgot to set matrix mode correctly. make the projection and modelview
matrices correct.
glPushMatrix();
if (translateFlag) //this is set to true in the keyboard function
//probably your key hit function is not working properly (I can't say without looking at full code)
{
x += 10;
glTranslated(x, 0, 0);
translateFlag = false;
}
drawCircle();
glPopMatrix();
//more drawings
// you are using glFlush() ????? try swapbuffers. exact function depends
on the API you are using (GLUT GLFW etc.)
}
相关文章:
- 如何定义在用作函数参数时工作的类模板的转换
- 将双精度值转换为 char 变量时字符串流如何工作
- 隐式转换是否应该在模板参数的上下文中工作?
- strcmp/char* 转换无法按预期工作
- 如何在 Poco 中将工作 HTTP 代码转换为 HTTPS
- Qt-工作线程崩溃时将cv::Mat转换为QImage
- 我的代码在作为参数传入 .begin() 时不起作用,但在我将 .begin() 转换为迭代器后工作
- 字符串文字到 char 数组的转换如何在C++中实际工作
- 将缓冲区转换为在现有程序中工作的iStream
- 更新MySQL连接器后,隐式转换停止工作
- 为什么Arduino(小端序)上的Sha1在没有转换为大端序的情况下工作?
- 如何使转换功能工作?
- 以下对二进制转换代码的小数如何工作
- 隐式转换未按预期工作
- 尝试将工作python程序转换为C++但不起作用
- 字符串到字符指针的转换如何在C++中工作
- 如何将负数转换为更广泛的类型在内部工作
- 十六进制、二进制和 oct 到 dec 转换器无法正常工作C++
- C++到C的转换工作流程
- C++如何用引用进行转换工作