我最近刚刚开始看opengl,以下的程序是《openGL超级宝典》上第3章的一个例子,输出的结果应该是一个螺旋曲线。但是在我的电脑上输出的结果却只是一个大的、中间为空心的的圆饼。我想请问一下各位是什么原因(是不是硬件原因)?
我的电脑主板名称 Asus P5PE-VM
显示卡(主板集成) Intel 82865G Graphics Controller [A-2]程序如下:
// Pointsz.c
// OpenGL SuperBible, Chapter 4
// Demonstrates OpenGL Primative GL_POINTS with point size
// Program by Richard S. Wright Jr.#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>
// Define a constant for the value of PI
#define GL_PI 3.1415f// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;
// Called to draw scene
void RenderScene(void)
{
GLfloat x,y,z,angle; // Storeage for coordinates and angles
GLfloat sizes[2]; // Store supported point size range
GLfloat step; // Store supported point size increments
GLfloat curSize; // Store current size // Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Get supported point size range and step size
glGetFloatv(GL_POINT_SIZE_RANGE,sizes);
glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step);
// Set the initial point size
curSize = sizes[0]; // Set beginning z coordinate
z = -50.0f; // Loop around in a circle three times
for(angle = 0.0f; angle <= (2.0f*3.1415f)*3.0f; angle += 0.1f)
{
// Calculate x and y values on the circle
// Specify the point size before the primative is specified
glPointSize(curSize);
x = 50.0f*sin(angle);
y = 50.0f*cos(angle);
// Draw the point
glBegin(GL_POINTS);
glVertex3f(x, y, z);
glEnd(); z += 0.5f;
curSize += step;
// Bump up the z value and the point size
} // Restore matrix state
glPopMatrix(); // Flush drawing commands
glutSwapBuffers();
}// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set drawing color to green
glColor3f(0.0f, 1.0f, 0.0f);
}void SpecialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
xRot-= 5.0f; if(key == GLUT_KEY_DOWN)
xRot += 5.0f; if(key == GLUT_KEY_LEFT)
yRot -= 5.0f; if(key == GLUT_KEY_RIGHT)
yRot += 5.0f; if(key > 356.0f)
xRot = 0.0f; if(key < -1.0f)
xRot = 355.0f; if(key > 356.0f)
yRot = 0.0f; if(key < -1.0f)
yRot = 355.0f; // Refresh the Window
glutPostRedisplay();
}
void ChangeSize(int w, int h)
{
GLfloat nRange = 100.0f; // Prevent a divide by zero
if(h == 0)
h = 1; // Set Viewport to window dimensions
glViewport(0, 0, w, h); // Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Points Size Example");
glutReshapeFunc(ChangeSize);
glutSpecialFunc(SpecialKeys);
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop(); return 0;
}
我的电脑主板名称 Asus P5PE-VM
显示卡(主板集成) Intel 82865G Graphics Controller [A-2]程序如下:
// Pointsz.c
// OpenGL SuperBible, Chapter 4
// Demonstrates OpenGL Primative GL_POINTS with point size
// Program by Richard S. Wright Jr.#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>
// Define a constant for the value of PI
#define GL_PI 3.1415f// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;
// Called to draw scene
void RenderScene(void)
{
GLfloat x,y,z,angle; // Storeage for coordinates and angles
GLfloat sizes[2]; // Store supported point size range
GLfloat step; // Store supported point size increments
GLfloat curSize; // Store current size // Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT); // Save matrix state and do the rotation
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Get supported point size range and step size
glGetFloatv(GL_POINT_SIZE_RANGE,sizes);
glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step);
// Set the initial point size
curSize = sizes[0]; // Set beginning z coordinate
z = -50.0f; // Loop around in a circle three times
for(angle = 0.0f; angle <= (2.0f*3.1415f)*3.0f; angle += 0.1f)
{
// Calculate x and y values on the circle
// Specify the point size before the primative is specified
glPointSize(curSize);
x = 50.0f*sin(angle);
y = 50.0f*cos(angle);
// Draw the point
glBegin(GL_POINTS);
glVertex3f(x, y, z);
glEnd(); z += 0.5f;
curSize += step;
// Bump up the z value and the point size
} // Restore matrix state
glPopMatrix(); // Flush drawing commands
glutSwapBuffers();
}// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set drawing color to green
glColor3f(0.0f, 1.0f, 0.0f);
}void SpecialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
xRot-= 5.0f; if(key == GLUT_KEY_DOWN)
xRot += 5.0f; if(key == GLUT_KEY_LEFT)
yRot -= 5.0f; if(key == GLUT_KEY_RIGHT)
yRot += 5.0f; if(key > 356.0f)
xRot = 0.0f; if(key < -1.0f)
xRot = 355.0f; if(key > 356.0f)
yRot = 0.0f; if(key < -1.0f)
yRot = 355.0f; // Refresh the Window
glutPostRedisplay();
}
void ChangeSize(int w, int h)
{
GLfloat nRange = 100.0f; // Prevent a divide by zero
if(h == 0)
h = 1; // Set Viewport to window dimensions
glViewport(0, 0, w, h); // Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
else
glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Points Size Example");
glutReshapeFunc(ChangeSize);
glutSpecialFunc(SpecialKeys);
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop(); return 0;
}
解决方案 »
- error LNK2001: unresolved external symbol _DirectSoundCaptureCreate8@12如何解决?
- 请问如何才能让使用GDI+画出来的字看好些呢
- 预定义问题,请大家帮忙
- 谁知道CZoomVew视图缩放源程序在哪里啊?
- 如何在辅助线程中安全的访问主线程控件?
- 如何获得另一个进程创建的窗口的某个子窗口的标题?
- 我只想要一个最简单的ATL COM源码
- 能否让编译器对某一函数或者某一文件不进行优化或者进行与工程文件设置不同的优化
- 在MFC中使用OPENGL的键盘功能回调函数
- 请大家公证的评论一下c++ builder和visual c++哪一个更好!
- 请教:3ds Max8制作的模型转换为.X文件模型显示时出现问题
- 界面刷新时如何使On_Draw以外地方的绘图不消失?
这个程序支持键盘操作。如果不调整弹簧的角度的话,默认会从底部看向头部,效果就是你说的那种情况。按 上下左右 看看?