I am new in OpenGL. I will be glad to get a little help from you.
Is it possible making a dot in screen according to coordinates that came from array in OpenGL.
For example I have
x=2 , y=2, and z=2
In the array there could be thousands of reference points. I need to make a shape from the points in the array.I am working in a 3D view. is this possible ? Anyone can get me through this? Thanks in advance.
I got his useful.
#include
#include
#include <iostream>
struct Point {
GLfloat x, y, z;
Point(GLfloat x, GLfloat y, GLfloat z): x(x), y(y), z(z) {
}
Point midpoint(Point p) {
return Point((x+p.x)/2, (y+p.y)/2, (z+p.z)/2);
}
};
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return;
}
void foo() {
static Point vertices[4] = {
Point(-25, -22, -20),
Point(-15, -22, -70),
Point(25, -22, -27),
Point(0, 45, -5)
};
static Point lastPoint = vertices[0];
glBegin(GL_POINTS);
for (int i = 0; i <= 200; i++) {
lastPoint = lastPoint.midpoint(vertices[rand() % 4]);
GLfloat intensity = (600 + lastPoint.z) / 400.0;
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(lastPoint.x, lastPoint.y, lastPoint.z);
}
glEnd();
glFlush();
}
void reshape(GLint w, GLint h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(100.0, GLfloat(w)/GLfloat(h), 10.0, 1500.0);
}
void init(void) {
glEnable(GL_DEPTH_TEST);
return;
}
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(foo);
init();
glutMainLoop();
return 0;
}