opengl颜色与颜色;多维数据集工作不正常
/* glutInitDisplayMode-初始化显示模式 GLUT_DOUBLE-允许在双缓冲区窗口上显示 GLUT_RGBA-显示颜色(红色、绿色、蓝色)和alpha GLUT_深度-允许深度缓冲 */ glutInitDisplayMode(GLUT_深度| GLUT_双精度| GLUT_RGB) 我这里没有任何立方体 你会得到一个立方体。它只是轴相交的那个小斑点。当你画一个2个单位大,大约160个单位远,视野70度的物体时,你还希望看到什么 我面临的另一个问题是,如果我不使用上面提到的变换属性,颜色就不起作用。 […]我得到默认的彩色圆锥体 我不知道你说的是什么意思。“默认颜色”将是GL内置颜色属性的初始值,即opengl颜色与颜色;多维数据集工作不正常,opengl,glut,Opengl,Glut,/* glutInitDisplayMode-初始化显示模式 GLUT_DOUBLE-允许在双缓冲区窗口上显示 GLUT_RGBA-显示颜色(红色、绿色、蓝色)和alpha GLUT_深度-允许深度缓冲 */ glutInitDisplayMode(GLUT_深度| GLUT_双精度| GLUT_RGB) 我这里没有任何立方体 你会得到一个立方体。它只是轴相交的那个小斑点。当你画一个2个单位大,大约160个单位远,视野70度的物体时,你还希望看到什么 我面临的另一个问题是,如果我不使用上面提到的
(1,1,1,1)
-白色。使用您设置的代码,您将获得之前设置的颜色。所以我唯一能做的猜测是,你没有正确地考虑GL的状态机,把自己弄糊涂了
但除此之外,您根本不应该使用这些代码—这是使用固定函数管道和即时模式绘图—这些功能自十年以来就被弃用,OpenGL的现代核心配置文件根本不支持这些功能。试图在2017年学习这些东西是浪费时间。顺便说一句:
没有。只是不。OpenGL没有“主循环”。GLUT不是OpenGL。老实说,这太可怕了。谢谢你的回答。这是我大学计算机图形学系提供的一个模板。他在这门课程中教授的平台和编码让我头晕目眩!令人痛苦的是,我没有任何与我的老师的方法完全匹配的教程。你还说这很可怕:'(我真的不知道该怎么办,因为没有办法退出课程。嗯,我不知道你的问题到底是什么。我确实解释了为什么你在没有缩放的情况下看不到立方体。如果我不知道圆锥体的颜色有什么问题,我确实尝试了你问题中的实际代码,所有的东西都像它应该的那样出现。就大学图形课程而言:是的,有很多课程教授20年前的OpenGL。是的,通常你不能对它做太多的反对,但这并不能改变它太可怕的事实。我没有读过你的问题,但请使用现代OpenGL。有很多旧的教程。是最好的网站之一吗我看到了。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<GL/glut.h>
double cameraAngle;
void grid_and_axes() {
// draw the three major AXES
glBegin(GL_LINES);
//X axis
glColor3f(0, 1, 0); //100% Green
glVertex3f(-150, 0, 0);
glVertex3f(150, 0, 0);
//Y axis
glColor3f(0, 0, 1); //100% Blue
glVertex3f(0, -150, 0); // intentionally extended to -150 to 150, no big deal
glVertex3f(0, 150, 0);
//Z axis
glColor3f(1, 1, 1); //100% White
glVertex3f(0, 0, -150);
glVertex3f(0, 0, 150);
glEnd();
//some gridlines along the field
int i;
glColor3f(0.5, 0.5, 0.5); //grey
glBegin(GL_LINES);
for (i = -10; i <= 10; i++) {
if (i == 0)
continue; //SKIP the MAIN axes
//lines parallel to Y-axis
glVertex3f(i * 10, -100, 0);
glVertex3f(i * 10, 100, 0);
//lines parallel to X-axis
glVertex3f(-100, i * 10, 0);
glVertex3f(100, i * 10, 0);
}
glEnd();
}
void display() {
//codes for Models, Camera
//clear the display
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0, 0, 0); //color black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear buffers to preset values
/***************************
/ set-up camera (view) here
****************************/
//load the correct matrix -- MODEL-VIEW matrix
glMatrixMode(GL_MODELVIEW); //specify which matrix is the current matrix
//initialize the matrix
glLoadIdentity(); //replace the current matrix with the identity matrix [Diagonals have 1, others have 0]
//now give three info
//1. where is the camera (viewer)?
//2. where is the camera looking?
//3. Which direction is the camera's UP direction?
//gluLookAt(0,-150,20, 0,0,0, 0,0,1);
gluLookAt(150 * sin(cameraAngle), -150 * cos(cameraAngle), 50, 0, 0, 0, 0, 0, 1);
/*************************
/ Grid and axes Lines
**************************/
grid_and_axes();
/****************************
/ Add your objects from here
****************************/
/*glColor3f(1, 0, 0);
glutSolidCone(20, 20, 20, 20);
glColor3f(0, 0, 1);
GLUquadricObj *cyl = gluNewQuadric();
gluCylinder(cyl, 10, 10, 50, 20, 20);
glTranslatef(0, 0, 50);
glColor3f(1, 0, 0);
glutSolidCone(10, 20, 20, 20);
*/
glColor3f(1, 0, 0);
glutSolidCube(1);
//ADD this line in the end --- if you use double buffer (i.e. GL_DOUBLE)
glutSwapBuffers();
}
void animate() {
//codes for any changes in Models, Camera
cameraAngle += 0.001; // camera will rotate at 0.002 radians per frame.
//codes for any changes in Models
//MISSING SOMETHING? -- YES: add the following
glutPostRedisplay(); //this will call the display AGAIN
}
void init() {
//codes for initialization
cameraAngle = 0; //angle in radian
//clear the screen
glClearColor(0, 0, 0, 0);
/************************
/ set-up projection here
************************/
//load the PROJECTION matrix
glMatrixMode(GL_PROJECTION);
//initialize the matrix
glLoadIdentity();
/*
gluPerspective() — set up a perspective projection matrix
fovy - Specifies the field of view angle, in degrees, in the y direction.
aspect ratio - Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
zNear - Specifies the distance from the viewer to the near clipping plane (always positive).
zFar - Specifies the distance from the viewer to the far clipping plane (always positive).
*/
gluPerspective(70, 1, 0.1, 10000.0);
}
int main(int argc, char **argv) {
glutInit(&argc, argv); //initialize the GLUT library
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Some Title");
init(); //codes for initialization
glEnable(GL_DEPTH_TEST); //enable Depth Testing
glutDisplayFunc(display); //display callback function
glutIdleFunc(animate); //what you want to do in the idle time (when no drawing is occuring)
glutMainLoop(); //The main loop of OpenGL
return 0;
}
glutMainLoop(); //The main loop of OpenGL