Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Oct 2012
Offline Last Active Oct 28 2015 06:24 PM

Posts I've Made

In Topic: using directly gluLookAt instead of glScalef

27 October 2015 - 06:49 PM

Thanks for your remarks, I think where the issue comes from :


I have in the source code above (GLWidget.cpp) :

extern const char *vertexShader;

GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
  m_particleRadius = 0.6f;
  m_pointScale = 100.0f;
  w_width = 600;
  w_height = 600;
  g_nearPlane = 0.1f;
  g_farPlane = 1000.0f;



void GLWidget::draw()
// Boolean for initializing the first display of the scene
if (isDisplayFirst)
isDisplayFirst = false;
// Create VBO
// Reset line scale value
// lineScaleValue = abs(Galaxy->pos[3]-Galaxy->pos[0])*3;
lineScaleValue = 100.0f;
// Initialize View
glViewport(0, 0, w_width, w_height);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// perspective good initial
gluPerspective(45.0f, (float) w_width/w_height, g_nearPlane, g_farPlane);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrixi
// I would like to remove the two lines below and put directly
// gluLookAt (0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// This way, the camera would be put at z = 3 / 0.03 = 100
gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(0.03f, 0.03f, 0.03f);
glClearColor(0.0 ,0.0, 0.0, 0.0);
glBlendFunc (GL_SRC_ALPHA, GL_ONE);
glUniform1f( glGetUniformLocation(mprogram, "pointRadius"), m_particleRadius );
glUniform1f( glGetUniformLocation(mprogram, "pointScale"),m_pointScale);
// Drawing particles
// see the following into above code snippet


void GLWidget::initializeGL()
  LoadGLTextures();  // load the textures.
  glClearColor(0.0 ,0.0, 0.0, 0.0);
  mprogram = compileProgram(vertexShader);



is defined into shaders.cpp :

#define STRINGIFY(A) #A

// vertex shader
const char *vertexShader = STRINGIFY(
uniform float pointRadius;  // point size in world space
uniform float pointScale;   // scale to calculate size in pixels
void main()
    // calculate window-space point size
    vec3 posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
    float dist = length(posEye);
    gl_PointSize = pointRadius * (pointScale / dist);
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);

    gl_FrontColor = gl_Color;

If I replace

gl_PointSize = pointRadius * (pointScale / dist);


gl_PointSize = 20.0

then the particles are displayed but their size doesn't increase when I zoom the scene.


Could you explain how to keep the original formula (gl_PointSize = pointRadius * (pointScale / dist);) and in the same time having scaling when zooming ?


it seems that variable

float dist = length(posEye);

is too high in this formula, so the size of the particles are too small to be visible.


How to circumvent this issue knowing I have the following values for particle radius and pointScale :

m_particleRadius = 0.6f;
m_pointScale = 100.0f;


In Topic: OpenGL / HUD - Computation of a good initial value for scale line

16 January 2013 - 05:12 PM

Its impossible to give one number for how wide it is without a distance.



So when I do :


gluPerspective(45.0f, (float)w_width / w_height, g_nearPlane, g_farPlane);"
gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);


I can't say that the width and height are equals to : width = height = 2 *tan(45) * distance ;  with distance = 3 ?

In Topic: OpenGL / HUD - Computation of a good initial value for scale line

16 January 2013 - 06:03 AM

I am not sure I have all understood. There are 2 things :

- the line I draw is done in "headupdisplay" function by :

//Setup for 2D  
  glOrtho(0, w_width, w_height, 0, -1, 1); 
// begin draw scale line 
  glVertex2d(350, 12); 
 glVertex2d(450, 12); 
 glVertex2d(350, 9);
  glVertex2d(350, 15);
  glVertex2d(450, 9); 
 glVertex2d(450, 15);
 // end draw  
glMatrixMode( GL_PROJECTION ); 
glMatrixMode( GL_MODELVIEW );  
  // end for 2D
So, this line has 100 pixel length.

- I want the value right to this line to represent the distance of the foreground plane, i.e the 2D projection of the 3D scene.

For example, I show you the result when I zoom (the value equals to 45.8 kpc) :

Attached File  test3.png   241.05KB   46 downloads

Now another picture with the same zoom but with also a rotation by mouse, this is a view by side of the galaxy :

Attached File  test4.png   126.61KB   59 downloads

wintertime, you say this distance is difficult to calculate correctly with perspective projection, could you give me some clue ?

I just want to get a value corresponding to the foreground objects, i.e the 2D projection in (xy) plane of the 3D scene without taking into account of the z coordinates. That's why you advise me to use Ortho projection ?


In Topic: OpenGL / HUD - Computation of a good initial value for scale line

16 January 2013 - 04:25 AM

I don't understand why I have to use Ortho projection, Perspective allows me to make diplay  particles smaller/bigger when they get far away/closer (with zoom out/in that I have implemented) while Ortho is for 2D stuff.

In Topic: draw multiple 2D textured elements at once

30 October 2012 - 08:43 AM

Thanks a lot mhagain, It works ! I understand better now. Actually, I was confusing between array passed to glVertexPointer and glTexCoordPointer. Your code shows that we have to compute the coordinates of each quad vertex and this FOR each body. I thought that we would just need the "raw" positions of each body (containing in the "pos" array) without doing the shift.

So now, I am going to increase the performance of display by using texured objects with VBO.

Maybe I will bore you again on this forum :)