PDA

View Full Version : Different questions...



dvwood
01-11-2009, 04:21 AM
Here are some n00b questions, hope you can help me out ;-)

a) How can 4x Anti-Aliasing be implemented?


b1.) What is fog used for in real-time rendering?
b2.) What about the fog parameters in OpenGL?

c) What is the role of the rasterizer in the rendering pipeline?


d) Give 4 examples of steps/events that occur during the rasterizer stage!?

ZbuffeR
01-11-2009, 08:02 AM
Come on, read the specs :
http://www.opengl.org/registry/doc/glspec21.20061201.pdf

If you let other people answer these questions for you, you will not learn.

At least provide some hypothesis on your own.

dvwood
01-11-2009, 10:21 AM
Since i am pressured by time, as i have to go through more than 8 chapters in the OpenGL Superbible, i havnet gotten that far with the rasterizer and fog. Thats why I am asking, and i would appreciate some help, i am not intentionally having other people solving my problems.
Thank you for the link, the pdf looks very useful.

Also does anyone know where i can download the math3D library? I have a problem installing the one from SuperBible examples. I got some errors (matrix-related) when i try to add it to my own project.

_NK47
01-12-2009, 06:15 AM
fyi: your teacher would not give you questions you actually never discussed in your lessons.

a) not precise enough. for code and theory look here: http://developer.nvidia.com/object/gdc_ogl_multisample.html

b1) for displaying fog (nice effect) and to cover up the clipping of objects at far clipping plane.
b2) ?

d) convert vertices to raster image, map vertices to the viewport, perspective division, clipping.

satan
01-12-2009, 06:38 AM
... i am not intentionally having other people solving my problems.
So it is just by pure chance that the questions you need answers to turn up on this forum?
Sounds like magic.

b2) They suck. Much better to implement your own (volumetric) fog. Looks so much better. ;)

_NK47
01-12-2009, 07:31 AM
b2) now i know. true, they suck and are somewhat limited (linear fog). like satan said its better to implement volumetric fog or radial fog or whatever fog. still, good enough for FFP.

dvwood
01-12-2009, 08:32 AM
Thanks for your answers, i appreciate it.


So it is just by pure chance that the questions you need answers to turn up on this forum?
Sounds like magic.


Life is too short and this is an open forum, where you can either waste your time making stupid remarks or choose to answer the questions. But thanks for the heads-up... ;)

I did implement fog, but it looks terrible.


glEnable(GL_FOG); // Turn Fog on
glFogfv(GL_FOG_COLOR, fLowLight); // Set fog color to match background
glFogf(GL_FOG_START, 10.0f); // How far away does the fog start
glFogf(GL_FOG_END, 30.0f); // How far away does the fog stop
glFogi(GL_FOG_MODE, GL_EXP2); // Which fog equation do I use?


No matter how i twist and turn the START and END values, it still looks way too foggy... any thoughts? are these values for the z-axis, or how can these be understood?

ZbuffeR
01-12-2009, 10:33 AM
I recommend to use glFogi(GL_FOG_MODE,GL_LINEAR) instead of GL_EXP2, as linear mode do really go from START to END linearly.
Be sure your scene is tightly enclosed by the start and end values, and that you have sufficient tesselation (classic fog is only calculated on vertices, then interpolated).
See "2. Poor Tessellation Hurts Lighting" here, it is similar :
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/


Linear attenuation on fog is less mathematically correct, but often appears nicer to the eye, and is easier to tune too.

ZbuffeR
01-12-2009, 10:35 AM
The distance is approximated with eye-z.
Be sure to have your projection and modelview matrices correctly set up (ie. do not rotate the projection matrix unless you know what you are doing).

dvwood
01-12-2009, 03:54 PM
Ok, to be fully honest check out my mess.
I have a huge problem that i have been battling with, thats why i am asking about the normals in the first place, then i thought it was the fog that caused the problem and so on and so on.... This is my first OpenGL implementation, i am a super and total n00b at this, and i have been trying to learn this these past 3-4 days. My problem is that i have defined 6 quads but only 2 of them are showing, every time i try to set the lighting model (ambient, diffuse, specular)... and i also have a spotlight in there somewhere....

I know this a long block of code, but i would really appreciate if you could help me out, cause i cant figure whats wrong with this...




#include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>



GLfloat rotVar = 0.0f;

// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;


GLfloat fLightPos[4] = { -100.0f, 100.0f, 50.0f, 1.0f }; // Point source
GLfloat fNoLight[] = { 0.0f, 0.0f, 0.0f, 0.0f };
GLfloat fLowLight[] = { 0.45f, 0.45f, 0.45f, 1.0f };
GLfloat fBrightLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };





void RenderScene(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);



glPushMatrix();
glLoadIdentity(); //
glTranslated(0.0f, 0.0f, -10.0f); // selve kuglen
//keyboard variables
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);



glRotated(rotVar, 0.0, 5.0, 0.0);


//RED WALL - left side
glColor3f(1.f, 0.23f, 0.25f);
glBegin(GL_QUADS);
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-200.0f, 125.3f, -100.0f);
glVertex3f(-100.0f, 100.3f, 100.0f);
glVertex3f(-100.0f, -25.3f, 100.0f);
glVertex3f(-200.0f, -25.3f, -100.0f);
glEnd();


//GREY WALL - rightside
glColor3f(0.62f, 0.62f, 0.62f);
glBegin(GL_QUADS);
glNormal3f(0.0f, -1.0, 0.0f);
glVertex3f(200.0f, 125.3f, -100.0f);
glVertex3f(100.0f, 100.3f, 100.0f);
glVertex3f(100.0f, -25.3f, 100.0f);
glVertex3f(200.0f, -25.3f, -100.0f);
glEnd();


//Ceiling
glColor3f(0.50f, 0.50f, 0.50f);
glBegin(GL_QUADS);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(-200.0f, 110.3f, -100.0f);
glVertex3f(-100.0f, 110.3f, 100.0f);
glVertex3f(100.0f, 110.3f, 100.0f);
glVertex3f(200.0f, 110.3f, -100.0f);
glEnd();


//FLOOR
glColor3f(0.35f, 0.35f, 0.35f);
glBegin(GL_QUADS);
glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-2000.0f, -250.3f, -1000.0f);
glVertex3f(-1000.0f, -250.3f, 100.0f);
glVertex3f(1000.0f, -250.3f, 100.0f);
glVertex3f(2000.0f, -250.3f, -100.0f);
glEnd();


//END WALL
glColor3f(0.61f, 0.60f, 0.60f);
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, -1.0f);
glVertex3f(-800.0f, -25.3f, -800.0f);
glVertex3f(-800.0f, 125.3f, -800.0f);
glVertex3f(800.0f, 125.3f, -800.0f);
glVertex3f(800.0f, -25.3f, -800.0f);
glEnd();

rotVar +=0.1f;
//glRotated(rotVar, 0.0, 0.0, 0.0);



glColor3ub(100,23,25);
glutSolidSphere(1.0f, 30, 17);



glTranslated(3.0f, 1.4f, -1.0f);


//CUBE AND COLORS

GLfloat black[3] = {0,0,0};
GLfloat red[3] = {1,0,0};
GLfloat blue[3] = {0,0,1};
GLfloat green[3] = {0,1,0};
GLfloat magenta[3] = {1,0,1};
GLfloat yellow[3] = {1,1,0};
GLfloat cyan[3] = {0,1,1};
GLfloat white[3] = {1,1,1};

glBegin(GL_QUADS);
glNormal3f(0,0,1);
glColor3fv(black);
glVertex3fv(black);
glColor3fv(red);
glVertex3fv(red);
glColor3fv(magenta);
glVertex3fv(magenta);
glColor3fv(blue);
glVertex3fv(blue);

glNormal3f(0,-1,0);
glColor3fv(yellow);
glVertex3fv(yellow);
glColor3fv(red);
glVertex3fv(red);
glColor3fv(black);
glVertex3fv(black);
glColor3fv(green);
glVertex3fv(green);

glNormal3f(0,0,-1);
glColor3fv(cyan);
glVertex3fv(cyan);
glColor3fv(white);
glVertex3fv(white);
glColor3fv(yellow);
glVertex3fv(yellow);
glColor3fv(green);
glVertex3fv(green);

glNormal3f(-1,0,0);
glColor3fv(green);
glVertex3fv(green);
glColor3fv(black);
glVertex3fv(black);
glColor3fv(blue);
glVertex3fv(blue);
glColor3fv(cyan);
glVertex3fv(cyan);



glNormal3f(1,0,0);
glColor3fv(white);
glVertex3fv(white);
glColor3fv(magenta);
glVertex3fv(magenta);
glColor3fv(red);
glVertex3fv(red);
glColor3fv(yellow);
glVertex3fv(yellow);

glNormal3f(0,1,0);
glColor3fv(cyan);
glVertex3fv(cyan);
glColor3fv(blue);
glVertex3fv(blue);
glColor3fv(magenta);
glVertex3fv(magenta);
glColor3fv(white);
glVertex3fv(white);

glEnd();

// Restore the matrix state
glPopMatrix();
// Refresh the Window
glutPostRedisplay();
glutSwapBuffers();

}










void SetupRC() {


///////////////////////////////////////////////////////////
//ALL LIGHT: SPECULAR, AMBIENT, DIFFUSE + SPOTLIGHTs



GLfloat lightPos[] = { 10.0f, 10.0f, 10.0f, 1.0f }; // Array to specify position
GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f }; //the postion of AMBIENT light
GLfloat diffuseLight[] = { 1.7f, 1.7f, 1.7f, 1.0f };
GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };


glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST); // Hidden surface removal
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
glEnable(GL_CULL_FACE); // Do not calculate inside

// Enable lighting
glEnable(GL_LIGHTING);

// Setup and enable light 0
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);

glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,70.0f);

glEnable(GL_LIGHT0);

// Enable color tracking
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT, GL_SPECULAR,specref);
glMateriali(GL_FRONT,GL_SHININESS,128); // All materials hereafter have full specular reflectivity with a high shine

// Light blue background
//glClearColor(0.65f, 0.65f, 65.0f, 1.0f ); //clear buffer

glEnable(GL_NORMALIZE);



/*
///////////////////////////////////////////////////////////
//FOG FOG FOG FOG

// Setup Fog parameters
glEnable(GL_FOG); // Turn Fog on
glFogfv(GL_FOG_COLOR, fLowLight); // Set fog color to match background
glFogf(GL_FOG_START, 1.0f); // How far away does the fog start
glFogf(GL_FOG_END, 30.0f); // How far away does the fog stop
glFogi(GL_FOG_MODE, GL_LINEAR); // Which fog equation do I use?
*/



}




/////////////////////////////////////////////////////
// Handle arrow keys
void SpecialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
xRot-= 5.0f;

if(key == GLUT_KEY_DOWN)
xRot += 5.0f;

if(key == GLUT_KEY_LEFT)
yRot -= 5.0f;

if(key == GLUT_KEY_RIGHT)
yRot += 5.0f;

if(key > 356.0f)
xRot = 0.0f;

if(key < -1.0f)
xRot = 355.0f;

if(key > 356.0f)
yRot = 0.0f;

if(key < -1.0f)
yRot = 355.0f;

// Refresh the Window
glutPostRedisplay();
}










//CAMERA
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (height==0)
// CLIPPING PLANE: field of view of 150 degrees, near and far clipping planes 1.0 and 800
gluPerspective ( 50, float(width), 1.0, 1000.0 );
else
gluPerspective ( 50, float(width)/height, 1.0, 1000.0); //-1.0 tæt på kamera
glMatrixMode(GL_MODELVIEW);
}
//CAMERA


















int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); //GLUT_DOUBLE, dobbel buffer
glutInitWindowSize(600, 600 );
glutInitWindowPosition(100,100);
glutCreateWindow("Cube Animation");
glutSpecialFunc(SpecialKeys);
glutDisplayFunc(RenderScene);

glutReshapeFunc(reshape);
glEnable(GL_DEPTH_TEST);

SetupRC();

glutMainLoop();
return 0;

}

Jan
01-12-2009, 05:58 PM
AWESOME !

"Life is too short and this is an open forum, where you can either waste your time making stupid remarks or choose to answer the questions."

I choose to waste my time!