我的窗口正在OpenGL中调整大小
My window is sizing up in OpenGL
我想使我的窗口大小(800800),但是GL命令
glutInitWindowSize(800, 500);
不会以任何方式影响我的代码。Bellow是完整的源代码。
#include <stdio.h>
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <iostream>
#include <math.h>
using namespace std;
struct point{
GLfloat x;
GLfloat y;
};
float a,b;
void initGL() {
// Set "clearing" or background color
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black and opaque
}
/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current clearing color
// glutInitWindowSize(800, 800);
float i;
float radians;
struct point graph[1000];
struct point graphC[1000];
for(i = 0.0; i < 1000.0; i++) {
graph[(int)i].x = i/1000.0;
graph[(int)i].y = sqrt(pow(i/100,3) + a*i/100.0 + b)/10.0;
graphC[(int)i].x = i/1000;
graphC[(int)i].y = -1*sqrt(pow(i/100,3) + a*i/100.0 + b)/10.0;
}
glBegin(GL_POINTS);
for(int j = 0; j < 1000; j ++){
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(graph[j].x,graph[j].y);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(graphC[j].x,graphC[j].y);
}
glEnd();
for(i = 0.0; i > -1000.0; i--) {
graph[-1*(int)i].x = i/1000.0;
graph[-1*(int)i].y = sqrt(pow(i/100,3) + a*i/100.0 + b)/10.0;
graphC[-1*(int)i].x = i/1000;
graphC[-1*(int)i].y = -1*sqrt(pow(i/100,3) + a*i/100.0 + b)/10.0;
}
glBegin(GL_POINTS);
for(int j = 0; j < 1000; j ++){
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(graph[j].x,graph[j].y);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(graphC[j].x,graphC[j].y);
}
glEnd();
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
cout<<"Please enter in an";
cin>>a;
cout<<"Please enter in bn";
cin>>b;
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("Scientific Plot"); // Create window with the given title
glutInitWindowSize(800, 500); // Set the window's initial width & height
glutInitWindowPosition(400, 400); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register callback handler for window re-paint event
initGL(); // Our own OpenGL initialization
glutMainLoop(); // Enter the event-processing loop
return 0;
}
像glutInitWindowSize
这样的命令需要在glutCreateWindow
之前调用,否则它们将无效。创建窗口后,您可以通过调用glutReshapWindow
来更改窗口的大小。
相关文章:
- 为char数组调整zlib-zpipe
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 调整大小后指向元素值的指针unordered_map有效?
- 了解 GLM- openGL 中的相机转换
- 如何在全屏模式下(在OpenGL中)使背景透明
- 在C++中调整向量中的索引
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGl glm rotate
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- OpenGL在启用深度测试时不会丢弃我的碎片
- OpenGL-如何调整窗口大小
- 在opengl c++中禁用窗口大小调整
- Opengl 2d 调整大小
- 如何在 SDL2.0 OpenGL 中调整视口大小
- OpenGL - 无法调整 glutSolid二十面体()的大小?
- 调整我简单的OpenGL/GLUT窗口的大小会产生奇怪的线条
- 在OpenGL ES中调整由投影仪引起的失真
- OpenCL/OpenGL纹理互操作:调整OpenGL纹理的大小
- 我的窗口正在OpenGL中调整大小