PDA

View Full Version : Nothing Display

SionFly
09-01-2010, 12:53 PM
i have nothing to display out when function drawWater call in the DrawGlScene. Is it my GL_QUAD_STRIP problem??

#define GridSize 63

HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application

bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=FALSE; // Fullscreen Flag Set To Fullscreen Mode By Default

GLuint texture[1];

struct TGLCoord
{
float x,y,z;
};
TGLCoord Vertex [GridSize][GridSize];
TGLCoord Normals [GridSize][GridSize];

float Viscosity;
float Position [GridSize][GridSize];
float Velocity [GridSize][GridSize];
float xAngle, yAngle;

int DrawWater ()
{
int i,j;
float vLength;

for (i=2;i<GridSize-2;i++) //Calculate new velocity
{
for (j=2;j<GridSize-2;j++)
{
Velocity[i][j] = Velocity[i][j] + (Position[i][j] -
(4*(Position[i-1][j] + Position[i+1][j] + Position[i][j-1] + Position[i][j+1]) + // left, right, above, below
Position[i-1][j-1] + Position[i+1][j-1] + Position[i-1][j+1] + Position[i+1][j+1])/25) / 7; // diagonally across
}
}

for (i=2;i<GridSize-2;i++) //Calculate new ripple position
{
for (j=2;j<GridSize-2;j++)
{
Position[i][j] = Position[i][j] - Velocity[i][j];
Velocity[i][j] = Velocity[j][j] * Viscosity;
}
}

for (i=0;i<GridSize;i++) //Calculate new vertex coordianates
{
for (j=0;j<GridSize;j++)
{
Vertex[i][j].x = (i - GridSize/2)/GridSize*5;
Vertex[i][j].y = (Position[i][j] / 1024)/GridSize*3;
Vertex[i][j].z = (j - GridSize/2)/GridSize*5;
}
}

for (i=0;i<GridSize;i++) //Calculate new vertex normals
{
for (j=0;j<GridSize;j++)
{
if (0<i<GridSize &amp;&amp; 0<j<GridSize)
{
Normals[i][j].x = Position[i+1][j] - Position[i-1][j];
Normals[i][j].y = 2048;
Normals[i][j].z = Position[i][j+1] - Position[i][j-1];

vLength = sqrt (Normals[i][j].x*Normals[i][j].x + Normals[i][j].y*Normals[i][j].y + Normals[i][j].z*Normals[i][j].z);
if (!vLength)
{
Normals[i][j].x = Normals[i][j].x / vLength;
Normals[i][j].y = Normals[i][j].y / vLength;
Normals[i][j].z = Normals[i][j].z / vLength;
}
}
else
{
Normals[i][j].x = 0;
Normals[i][j].y = 1;
Normals[i][j].z = 0;
}
}
}

glBindTexture(GL_TEXTURE_2D, texture[0]); //Draw water texture

for (j=0;j<GridSize-1;j++)
{
for (i=0;i<GridSize;i++)
{
glNormal3fv(&amp;Normals([i][j+1]));

glVertex3fv(&amp;(Vertex[i][j+1].x));
glNormal3fv(&amp;(Normals[i][j].x));
glVertex3fv(&amp;(Vertex[i][j].x));

}
glEnd();
}

return TRUE;
}

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glTranslatef(0.0,0.2,-4.5);
// glColor3f(0.85, 1, 0.85);
DrawWater;

return TRUE;
}[/B][/color]

Jacek Nowak
09-02-2010, 04:34 AM
Try DrawWater(); :)

SionFly
09-02-2010, 05:36 AM
DrawWater() cannot also.. I don think this is the problem.. i think is about the content in between glBegin(GL_QUAD_STRIP) and glEnd.

ugluk
09-02-2010, 06:33 AM
Try to insert some debugging code. As for example, draw the quads as untextured wireframes, for example.

SionFly
09-09-2010, 08:56 AM
Normal triangle can, only what i want cannot...

HannesH
09-09-2010, 01:54 PM
glVertex3fv(&amp;(Vertex[i][j+1].x));
glNormal3fv(&amp;(Normals[i][j].x));
glVertex3fv(&amp;(Vertex[i][j].x));

Should be

glVertex3fv(&amp;(Vertex[i][j+1]));
glNormal3fv(&amp;(Normals[i][j]));
glVertex3fv(&amp;(Vertex[i][j]));

EDIT:

Sorry, I meant

glVertex3fv(&amp;(Vertex[i][j+1].x), &amp;(Vertex[i][j+1].y), &amp;(Vertex[i][j+1].z));

etc...

KylBlz
09-09-2010, 05:11 PM
glVertex3fv takes a pointer to {x,y,z}, we need to know more about the vertex structure hes using. try changing the vertex/normal structure to something like:

typedef struct vertex {
GLfloat xyz[2];
} vertex;

implementation:

vertex vert[] = {{0,0,0},
{0,1,0},
{1,1,0},
{1,0,0}}; // x,y,z
glVertex3fv(&amp;vert[0]);
glVertex3fv(&amp;vert[1]);
glVertex3fv(&amp;vert[2]);
glVertex3fv(&amp;vert[3]);
glEnd();

Do the same with your normals.

SionFly
09-09-2010, 08:48 PM
Sorry, got error.. Function glVertex3fv does not take 3 arguments.. And i display one by ones also nothing out.

KylBlz
09-10-2010, 01:08 AM
It takes one pointer to GLfloat {x,y,z}...

you could do: glVertex3f(&amp;Vertex[i][j+1].x, &amp;Vertex[i][j+1].y, &amp;Vertex[i][j+1].z);

== OR ==

glVertex3fv(&amp;vertex[i][j+1]);
^ BUT you would have to change the vertex structure to something like

typedef struct vertex {
GLfloat xyz[2];
} vertex;

However, this is mainly a problem with you C coding skills, not your knowledge of the OpenGL library..

SionFly
09-10-2010, 04:07 PM
Error occured...

error C2664: 'glVertex3fv' : cannot convert parameter 1 from 'vertex *' to 'const GLfloat *'

Savalia
09-11-2010, 01:16 AM
SionFly,
Are you using MS Visual Studio, I'm using the Express Edition 2008 and it will show errors if the loop counter isn't initialized, I find this happens a lot in older code:

for(i = 0: i < 5;++i)
{
//loop statements
}

for( int i = 0; i <5:++i)
{
//loop statements
}

Savalia
09-11-2010, 01:22 AM
glVertex3f(x,y,z)
glvertex3fv(array)

abolz
09-11-2010, 02:20 AM
Make sure you have initialized your arrays.
While calculating new vertex positions: The line

if (0<i<GridSize &amp;&amp; 0<j<GridSize)

compiles fine but will not give you the expected result. You should use

if (0 < i &amp;&amp; i < GridSize-1 &amp;&amp; 0 < j &amp;&amp; j < GridSize-1)

glNormal3fv(&amp;Normals([i][j+1]));

does not give you a compiler error?!?!?! You might also try to revert
the order of the vertex specification commands. Maybe you're looking to