Sign in to follow this  
Cire360

Help please!

Recommended Posts

First of all, i'd like to say thanks for the articles on openGL, you guys did a bang up job! Keep up the good work. Now lets get down to business. I have written a C++ program that calculates a large subset of x,y,z cordinates based on attractors. Now the resulting image looks like http://gpserver1.com/Cire/nebula.jpg. And now I want to begin porting this into opengl. Right now I just wana assign a blueish pixel to each x,y,z cord, but if it has a value already I wana compine it with the new value sorta 'adding' the values together, so if i hit a x,y,z cord over and over it gets brighter adn brighter. Future modifications to the program I want to make it so that its more of refactor or reflector picking up lighting from nearby stars so to speak so that the nebulas might have lighting from 2 different colored nearby stars. The problem is i have no idea how to go abouts setting pixels, I used the nehe framework and i just can't seem to get pixels in thier correct location, hell i'am lucky if the buggers show up at all. The application is 800x600 full screen. Any and all help would be GREATLY appreciated. I am also willing to throw the source code up if needed. ++Cire.

Share this post


Link to post
Share on other sites
You'll probably want to use orthogonal mode in OpenGL to set it to a "2D" mode. If you have GLU, the easiest way to do this is gluOrtho2D.

With the right parameters, you can map orthogonal mode to specific pixels, and then use the GL_POINT primitive to draw pixel-sized objects (direct pixel access is slow as modern video cards are not designed for such; GL_POINT uses 3D hardware accleration).

Share this post


Link to post
Share on other sites
Are you wanting to do the rendering with an orthographic projection?

If so, you will want to create your window (say... 800x600), then set the viewport...

glViewport(0, 0, 800, 600); // I *think* that's the signature...

Then you want to define the projection matrix...
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 0, 600, 0.0, farClipDist); //set how deep you want projection

Now you can just draw within that 800x600xfarClipDist box and everything will show up on the pixel corresponding to the (x,y) components of the coordinate. To draw a point on pixel 200,150 (from bottom left) you would call...

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_POINTS);
glVertex3f(200, 150, pointDepth);
... other points ...
glEnd();

If you want a perspective matrix, you want to use glPerspective to set up the projection matrix, but then the point X,Y won't necessarily correspond directly to the pixel X,Y (and won't 99.999999999% of the time [grin]).

If you want to just "add up" the intensities of the points drawn, you should look into using the accumulation buffer. Here is documentation for glAccum(...) to get you started. The accumulation buffer isn't the fastest thing in the world, so keep that in mind if you are wanting to do real-time stuff.

Share this post


Link to post
Share on other sites
Thank you so much guys, you rock so much!!! I really appreciate your help, i've learned more in that last post then 3 or 4 tutorials.

An updated image http://gpserver1.com/cire/nebula2.jpg

I have another question and that is, can 'pixels' done with glpoint be 'lighted' so to speak. Like i wana put 1 or 2 stars at vairous locations and, have them with different colors of lights that they emit, ie bluish or orangaish or redish, ect...Can these points be lighted like that, and if so, how?

++Cire.

Share this post


Link to post
Share on other sites
I've never actually tried it, to be honest. If it is possible, you will have to specify a normal, which may defeat the purposes of using "points". You would basically be treating them as little tiny fragments (like confetti or something), assuming you can light points. Superficially, it seems like it should be possible. The fixed function pipeline calculates lighting per-vertex.

You may want to consider implementing this whole thing in a shader... you could probably come up with some really cool stuff.

Share this post


Link to post
Share on other sites
To make this more realistic, shoudl i perhapse make them instead of pixels, maybe triangles, could I do alot more with it, i am sorry for the newbie questions i'am kinda new to this 3d stuff, as I think I stated before my experience is limited to pretty much direct draw stuff back in dx7.

As always thanks for your help.

++Cire.

Share this post


Link to post
Share on other sites
Well, if you don't want to go the shader route, you could try using tiny polygons. .. it might result in slower execution. I don't know about that, even, becuase points are supposed to be slower (I think). Before doing that, though, give the lit point approach a shot.

Just stick a glNormal(...) call in front of each point, so that it knows how to light it. Maybe randomize the normal vectors or something. I imagine it will probably work (I've just never lit points before).

Share this post


Link to post
Share on other sites
woah, lighting seems to work, well kinda at least. sadly its not how I expected it to be. I had hoped that by setting say a light source with 50% red value at say pixel 0,800, then part of the nebula would be slightly mapped to a redish color, instead the whole image no matter what itensity of color was on it its changed to red, kinda too cheesy to even show a screenshot of.

Am i doing something wrong, i'am using GL_AMBIENT, isn't that correct to indicate a source?

I tried implementing...

glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_SPECULAR, LightAmbient );
glLighti( GL_LIGHT1, GL_SPOT_EXPONENT, 100);
glLighti( GL_LIGHT1, GL_SPOT_CUTOFF, 90 );

glLightiv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable( GL_LIGHTING );

any suggestions?

++Cire.

Share this post


Link to post
Share on other sites
I've got most of the light figured out now, but I can't for the life of me figure out how to make it not adjust the alpha level of the pixel.

If pixel is barely visible it becomes very visiable when the redish light hits it so to speak in fact all pixles that compose the image becomes shaded with that light level. I applogize for not being able to explain this very well, but if i have an orgianl pixle at say 300,300,1 that is 0.0, 0.0, 1.0, 1.0 full blue, and a pixle next to it at say full blue with 0.2 alpha (barely visible), and a red light is turned on next to them they both take on the intensity and color, so both become that range of red.

Is it supposed to be this way? Is thier a way I can say don't adjust the alpha levels? Or am i doing tihs completly wrong?

As always thanks in advance for any and all help you can provide.

++Cire.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this