Question

I'm trying to display a point cloud with OpenGL.

I have followed some tutorials and I managed to display some geometric schema but when i try to display a point cloud read from a csv file, it does not work. The reading of file work very well.

the includes

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <boost/tokenizer.hpp>
#include <sstream>
#include <vector>

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <algorithm>

#include "Point.cpp"
#include "drawing.cpp"

using namespace std;

declarations

void draw(vector<Point> v);

int pointsNBR = 200;

char *theFileName;

main method

int main (int argc, char** argv) {

  if(argv[1]){
    theFileName = argv[1];
  }else{
    cout << "Please enter the file name !!\n";
    exit(0);
  }

  if(argv[2]){
    pointsNBR = atoi(argv[2]);
  }
  PCEngine(theFileName, pointsNBR);

    SDL_Init(SDL_INIT_VIDEO);
  atexit(SDL_Quit);
  SDL_WM_SetCaption("Point Cloud", NULL);
  SDL_SetVideoMode(720,640, 32, SDL_OPENGL);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(70,(double)640/480,1,1000);

  bool continuer = true;
  SDL_Event event;

  vector<Point> v = getCloudPoint(theFileName);
    draw(v);

  for (;;)    {
    SDL_WaitEvent(&event);
    switch(event.type){
        case SDL_QUIT:
        exit(0);
        break;
    }
  }

}

draw method

void draw(vector<Point> v){

  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glPushMatrix();

  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluLookAt(3,4,2,0,0,0,0,0,1);

  glPointSize(2.0);

  glBegin(GL_POINTS);
    for (size_t n = 0; n < v.size(); n++){
        glColor3ub(v[n].r, v[n].g, v[n].b);
        glVertex3d(v[n].x, v[n].y, v[n].z);
    }
  glEnd();

  glFlush();
  SDL_GL_SwapBuffers();

  glPopMatrix();
  glPopAttrib();
}

My problem is that I haven't any display.

Can someone help me please?

Was it helpful?

Solution

You should use the GL_MODELVIEW to position your cloud in the scene.

In the draw method change glMatrixMode(GL_PROJECTION); to glMatrixMode(GL_MODELVIEW);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top