LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-18-2009, 08:58 AM   #1
jamwaffles
Member
 
Registered: Mar 2008
Distribution: Ubuntu Lucid
Posts: 131

Rep: Reputation: 19
Question OpenGL point sprites - how can I change their size?


hi

I am writing a particle engine using point sprites, and i want to change the size of the points in relation to how far they are from the camera (you know, like in the real world). I've borrowed code from places and it uses glext to get the right functions.

so my questions are:

* How can i change the point size based on how far they are from the camera

* Do i used glext for linux (if it exists) or is there an alternative?

Rendering code:

Code:
glBindTexture(GL_TEXTURE_2D, textureID);
glEnable(GL_POINT_SPRITE);
	glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

	glBegin( GL_POINTS );

    	for(int z = 0; z < particleCount; z++)
	{	
		glPointSize(EmitterProperties.texsize);
		glColor4f(particles[z].colr, particles[z].colg, particles[z].colb, particles[z].life);
		glBegin(GL_POINTS);
			glVertex3f(particles[z].posx, particles[z].posy, particles[z].posz);
		glEnd();
	}
	glDisable(GL_POINT_SPRITE);
thanks in advance to any responses

james waples, 14

Last edited by jamwaffles; 02-18-2009 at 08:59 AM.
 
Old 02-19-2009, 06:40 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Try using small triangles instead. Points technically don't have any size at all, but in order to actually make them visible, pipelines make them 1 pixel large. Triangles do have size, so the pipeline should adjust their size properly. However, (without antialiasing) pipelines usually don't color the edges so very small or distant triangles will disappear.

As for glext, if you're using SDL, load the functions you want from with SDL_GL_GetProcAddress(). Be careful when using extensions cause you can easily lock out people who have older GPUs.
 
Old 02-20-2009, 04:59 AM   #3
jamwaffles
Member
 
Registered: Mar 2008
Distribution: Ubuntu Lucid
Posts: 131

Original Poster
Rep: Reputation: 19
Thumbs up

thankyou very much for that - i have gone back to using not triangles but textured squares for my particles, with no apparent decrease in framerate, which is odd. anyway, i've run into another problem being that the squares are rendered facing the vector (0, 0, 1) as in facing towards the screen with a reset camera. what i need to do now is make them face the camera wherver it is. The screenshots should explain this further. so, what i want to do is combine the point sprite turn-to-camera functionality with the rendering-squares-that-change-size functionality to produce particles that face the camera AND change their size according to the camera position. i have tried using glPointPerameterf(/glPointPerameteri, etc) to no avail as g++ says it hasn't been defined. do i need a particular library for this or should i use SDL which i dont really want to do. apologies for the long post, but this is the last problem to overcome before i have almost finished my particle engine (collision detection with normals next)

james

ps. particular libraries like glew, glext, all those opengl ones as i'd like to keep everything pure OpenGL to keep dependencies as low as possible (the only external libraries im using are GLPNG, which is excellent for png textures).
Attached Images
File Type: png Screenshot-Untitled Window.png (25.0 KB, 8 views)
File Type: png Screenshot-Untitled Window-1.png (16.9 KB, 4 views)
 
Old 02-20-2009, 06:17 AM   #4
Biddle
Member
 
Registered: Jan 2009
Posts: 37

Rep: Reputation: 17
Quote:
i've run into another problem being that the squares are rendered facing the vector (0, 0, 1) as in facing towards the screen with a reset camera. what i need to do now is make them face the camera wherver it is
This effect is called billboarding, there are numerous articles on how to do this but in this instance you probably want to use screen oriented billboarding. This involves using the inverse normal of the cameras view plane to orientate the polygon.
 
Old 02-20-2009, 10:43 AM   #5
jamwaffles
Member
 
Registered: Mar 2008
Distribution: Ubuntu Lucid
Posts: 131

Original Poster
Rep: Reputation: 19
yeah, um... i've sorted everything out now with the point sprites - i have managed to get attenuation to work with a lib called GLee. really useful it is too. thanks anyway everyone and i apologise for wasting your time

james
 
Old 02-20-2009, 10:47 AM   #6
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Quote:
ps. particular libraries like glew, glext, all those opengl ones as i'd like to keep everything pure OpenGL to keep dependencies as low as possible (the only external libraries im using are GLPNG, which is excellent for png textures).
If you want to use an extension, you have to either must use a platform-dependent API to get the extension function pointers from the GL library, or an external library that makes the using extensions cross-platform. I understand that you don't like dependencies, but I personally use SDL as my one dependency because it provides a lot of nice stuff and is one of the easiest libraries to set up in VS. The event system is a lot easier to deal with than GLUT. Loading pngs are pretty easy with SDL_Image. SDL_Image is technically a different library than base SDL, but in practice SDL_Image and SDL_Mixer don't act like separate dependancies.
 
Old 02-21-2009, 04:22 AM   #7
jamwaffles
Member
 
Registered: Mar 2008
Distribution: Ubuntu Lucid
Posts: 131

Original Poster
Rep: Reputation: 19
thankyou for the SDL suggestion, but i have found a library called GLee which has come in really handy. loading PNGs is a cinch with GLPNG, so everything's sorted. thankyou for your time anyway

james
 
  


Reply

Tags
c++, opengl, point, sprites


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fonts - is there a size transition point? GTrax Linux - Software 9 12-29-2008 06:02 AM
How do i change the size of a xterm window or lanch one with a specified size? Garavix Linux - Newbie 2 04-20-2006 10:06 PM
[opengl]multisampling, point parameters and fogcoordinates hylke Programming 6 08-24-2004 11:29 AM
ATI Radeon 7500 M works, but certain graphical elements (like sprites) flicker tuxedo-notebook Linux - Hardware 0 04-28-2004 12:32 AM
increase point size size when printing PDF files newlin Red Hat 0 09-27-2003 08:13 AM


All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration