OpenGL中GL_POINT绘制冰柱的问题 [英] problem in drawing cricle by GL_POINT in opengl
本文介绍了OpenGL中GL_POINT绘制冰柱的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用GL_POINT在opengl中绘制一个小钉,这里有我的代码:
I want draw a cricle in opengl by GL_POINT and there is my code:
#include "stdafx.h"
#include <glut.h>
#include <math.h>
const float PI =3.141592653;
void init()
{
glClearColor(1,1,1,0);
glShadeModel(GLU_FLAT);
glPointSize( 6.0 );
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// drawing
float x,y;
glColor3f(0,0,1);
glBegin(GL_POINT);
for ( float angle = 0; angle <= 2*PI; angle+=0.1)
{
x =( .3) * cos (angle);
y =( .3) * sin (angle);
glVertex2f(x,y);
}
glEnd();
glutSwapBuffers();
}
void main(int argc , char * argv[])
{
glutInit(& argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
// Window of drawing
glutInitWindowSize(500,500);
glutInitWindowPosition(100 , 100);
glutCreateWindow("my first program");
init();
glutDisplayFunc(display);
glutMainLoop();
}
但是当我运行程序时,我只会看到一个白色的窗口!,如果您有解决此问题的想法,请帮助我.
tnx:)
but when I run program I just see a white window!,if you have idea to solve it pliz help me.
tnx :)
推荐答案
您必须将glBegin和glEnd块放入循环中:
Hi ,
You must put glBegin and glEnd blocks inside the loop:
#include <glut.h>
#include <math.h>
const float PI =3.141592653;
void init()
{
glClearColor(1,1,1,0);
glShadeModel(GLU_FLAT);
glPointSize( 6.0 );
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// drawing
float x,y;
glColor3f(0,0,1);
for ( float angle = 0; angle <= 2*PI; angle+=0.1)
{
x =( 0.3) * cos (angle);
y =( 0.3) * sin (angle);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
glutSwapBuffers();
}
void main(int argc , char * argv[])
{
glutInit(& argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
// Window of drawing
glutInitWindowSize(500,500);
glutInitWindowPosition(100 , 100);
glutCreateWindow("my first program");
init();
glutDisplayFunc(display);
glutMainLoop();
}
如果将点大小更改为default,并在循环中使用更多步骤,则圆圈会更好:
The circle will be nicer , if you change point size to default , and use more steps in loop:
#include <glut.h>
#include <math.h>
const float PI =3.141592653;
void init()
{
glClearColor(1,1,1,0);
glShadeModel(GLU_FLAT);
//glPointSize( 6.0 );
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// drawing
float x,y;
glColor3f(0,0,1);
for ( float angle = 0; angle <= 2*PI; angle+=0.01)
{
x =( 0.3) * cos (angle);
y =( 0.3) * sin (angle);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
glutSwapBuffers();
}
void main(int argc , char * argv[])
{
glutInit(& argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
// Window of drawing
glutInitWindowSize(500,500);
glutInitWindowPosition(100 , 100);
glutCreateWindow("my first program");
init();
glutDisplayFunc(display);
glutMainLoop();
}
我很确定它没有用,因为您没有设置投影矩阵.
将此代码放入您的init函数中:
I''m pretty sure it doesn''t work because you didn''t set up your projection matrix.
Put this code inside your init function:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 500.0, 500.0, 0.0, 1.0, -1.0); //As an example
glMatrixMode(GL_MODELVIEW);
哦,还要在您的glClear(...)调用下添加
Oh, and also add
glLoadIdentity();
#include <glut.h>
//#include <glu.h>
#include <math.h>
const float PI = 3.141592653;
void init(void)
{
glClearColor(1,1,1,0);
glShadeModel(GLU_FLAT);
glPointSize(6.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 500.0, 500.0, 0.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
/**glBegin(GL_POINTS);
//drawing circle with points
glClearColor(1,1,1,0);
glShadeModel(GLU_FLAT);
glPointSize(6.0);
//glVertex2f(1.0f,0.2f);
//glVertex2f(0.5f,-0.5f);
glEnd;*/
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
//drawing
float x,y;
glColor3f(0,0,1);
for(float angle = 0; angle<=2*PI; angle+=0.1)
{
x =(0.3)*cos (angle);
y=(0.)*sin (angle);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd;
}//endFor
glutSwapBuffers();
/**glColor3f(1.0,0.0,0.0);
glVertex3f(1.0f,1.0f,1.0f);
glColor3f(1.0,0.0,0.0);
glVertex3f(-1.0f,-1.0f,0.0f);*/
}
void main(int argc, char** argv)
{
int mode = GLUT_RGB | GLUT_DOUBLE;
//int mode = GLUT_SINGLE depend of parity of your card
glutInit(& argc, argv);
glutInitDisplayMode(mode);//function initializing display mode
glutInitWindowSize(500,500);// size of window width & height pixel
glutInitWindowPosition(100,100);//(0,0) left bottom corner position
glutCreateWindow ("First Project");
init();
glutDisplayFunc(display);//name of the Object/Function
//gluSphere x = new gluSphere();
glutMainLoop();
//return 0;
}//endmain
这篇关于OpenGL中GL_POINT绘制冰柱的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文