Jump to content
  • Advertisement
Sign in to follow this  
PlutoWarrior

loop drawn quads for walls

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys I haven't posted in a while but I need some help. I'm coding a simple shooting game but with a few twists. Each players base has a wall around it. The wall is made up of individual textured quads. The vertices for the quads are found by just incrementing the first quads coordinates with a loop. The first base's wall works fine with all the quads drawn properly. The second one is draw properly up until the 22nd and 23rd quads on the wall. They are distorted with parts of each quad in the extreme sides of the screen.I can't seem to figure out why this is happening since all the coordinates are drawn by loops. Here's the code for the stucts I use and for the loops that set up the wall sections and draws them. These are all declared as global.

//Array and struct for wall sections
int lcv=0;
int         i=0;
float wallinc=16.0f;


typedef struct
{
    float pos_ver[2];
    float pos2_ver[2];
    float pos3_ver[2];
    float pos4_ver[2];
    unsigned int health;
    bool dead;
}WALL; 
   

typedef struct						// Create A Structure For Particle
{
	bool	active;					// Active (Yes/No)
	float	life;					// Particle Life
	float	fade;					// Fade Speed
	float	r;						// Red Value
	float	g;						// Green Value
	float	b;						// Blue Value
	float	x;						// X Position
	float	y;						// Y Position
	float	xi;						// X Direction
	float	yi;						// Y Direction
	float	xg;						// X Gravity
	float	yg;						// Y Gravity
}PARTICLES;							// Particles Structure   

typedef struct
{
    WALL wall[31]; 
    PARTICLES bullet[10];
    float power;
    float life;
    
    float base_pos_ver[2];
    float base_pos2_ver[2];
    float base_pos3_ver[2];
    float base_pos4_ver[2];
    
    float gunbase_pos_ver[2];
    float gunbase_pos2_ver[2];
    float gunbase_pos3_ver[2];
    float gunbase_pos4_ver[2];
    
    float turret_pos_ver[2];
    float turret_pos2_ver[2];
    float turret_pos3_ver[2];
    float turret_pos4_ver[2]; 
    
}PLAYER;

PLAYER player1;
PLAYER player2;   


This next part is the init function. Only the player2 wall is causing problems.
//origonal wall segment
   
    player1.wall[0].pos_ver[0]=0.0f; player1.wall[0].pos_ver[1]=304.0f+wallinc;
    player1.wall[0].pos2_ver[0]=0.0f+wallinc; player1.wall[0].pos2_ver[1]=304.0f+wallinc;
    player1.wall[0].pos3_ver[0]=0.0f+wallinc; player1.wall[0].pos3_ver[1]=304.0f;
    player1.wall[0].pos4_ver[0]=0.0f; player1.wall[0].pos4_ver[1]=304.0f;
    player1.wall[0].dead=false;
    
   //origonal wall2 segment
    player2.wall[0].pos_ver[0]=1024.0f-wallinc; player2.wall[0].pos_ver[1]=304.0f+wallinc;
    player2.wall[0].pos2_ver[0]=1024.0f; player2.wall[0].pos2_ver[1]=304.0f+wallinc;
       player2.wall[0].pos3_ver[0]=1024.0f; player2.wall[0].pos3_ver[1] = 304.0f;
    player2.wall[0].pos4_ver[0]=1024.0f-wallinc; player2.wall[0].pos4_ver[1] = 304.0f;
player2.wall[0].dead=false;

//draw the rest of the wall segments
    for(i=1;i<31;i++)
    {
       if (i<=10)
        {
            player1.wall.pos_ver[0]=player1.wall[i-1].pos_ver[0]+wallinc;
            player1.wall.pos_ver[1]=player1.wall[0].pos_ver[1];
            player1.wall.pos2_ver[0]=player1.wall[i-1].pos2_ver[0]+wallinc;
            player1.wall.pos2_ver[1]=player1.wall[0].pos2_ver[1];
            player1.wall.pos3_ver[0]=player1.wall[i-1].pos3_ver[0]+wallinc;
            player1.wall.pos3_ver[1]=player1.wall[0].pos3_ver[1];
            player1.wall.pos4_ver[0]=player1.wall[i-1].pos4_ver[0]+wallinc;
            player1.wall.pos4_ver[1]=player1.wall[0].pos4_ver[1];
            player1.wall.dead=false;
            player1.wall.health=100;
        }    
        if((i>10)&&(i<=20))
        {
            player1.wall.pos_ver[0]=player1.wall[10].pos_ver[0];
            player1.wall.pos_ver[1]=player1.wall[i-1].pos_ver[1]+wallinc;
            player1.wall.pos2_ver[0]=player1.wall[10].pos2_ver[0];
            player1.wall.pos2_ver[1]=player1.wall[i-1].pos2_ver[1]+wallinc;
            player1.wall.pos3_ver[0]=player1.wall[10].pos3_ver[0];
            player1.wall.pos3_ver[1]=player1.wall[i-1].pos3_ver[1]+wallinc;
            player1.wall.pos4_ver[0]=player1.wall[10].pos4_ver[0];
            player1.wall.pos4_ver[1]=player1.wall[i-1].pos4_ver[1]+wallinc;
            player1.wall.dead=false;
            player1.wall.health=100;
        }
        if(i>20)
        {
            player1.wall.pos_ver[0]=player1.wall[i-1].pos_ver[0]-wallinc;
            player1.wall.pos_ver[1]=player1.wall[20].pos_ver[1];
            player1.wall.pos2_ver[0]=player1.wall[i-1].pos2_ver[0]-wallinc;
            player1.wall.pos2_ver[1]=player1.wall[20].pos2_ver[1];
            player1.wall.pos3_ver[0]=player1.wall[i-1].pos3_ver[0]-wallinc;
            player1.wall.pos3_ver[1]=player1.wall[20].pos3_ver[1];
            player1.wall.pos4_ver[0]=player1.wall[i-1].pos4_ver[0]-wallinc;
            player1.wall.pos4_ver[1]=player1.wall[20].pos4_ver[1];
            player1.wall.dead=false;
            player1.wall.health=100;
        }
         
        if (i<=10)
        {
            player2.wall.pos_ver[0]=player2.wall[i-1].pos_ver[0]-wallinc;
            player2.wall.pos_ver[1]=player2.wall[0].pos_ver[1];
            player2.wall.pos2_ver[0]=player2.wall[i-1].pos2_ver[0]-wallinc;
            player2.wall.pos2_ver[1]=player2.wall[0].pos2_ver[1];
            player2.wall.pos3_ver[0]=player2.wall[i-1].pos3_ver[0]-wallinc;
            player2.wall.pos3_ver[1]=player2.wall[0].pos3_ver[1];
            player2.wall.pos4_ver[0]=player2.wall[i-1].pos4_ver[0]-wallinc;
            player2.wall.pos4_ver[1]=player2.wall[0].pos4_ver[1];
            player2.wall.dead=false;
            player2.wall.health=100;
        }
        
        if((i>10)&&(i<=20))
        {
            player2.wall.pos_ver[0]=player2.wall[10].pos_ver[0];
            player2.wall.pos_ver[1]=player2.wall[i-1].pos_ver[1]+wallinc;
            player2.wall.pos2_ver[0]=player2.wall[10].pos2_ver[0];
            player2.wall.pos2_ver[1]=player2.wall[i-1].pos2_ver[1]+wallinc;
            player2.wall.pos3_ver[0]=player2.wall[10].pos3_ver[0];
            player2.wall.pos3_ver[1]=player2.wall[i-1].pos3_ver[1]+wallinc;
            player2.wall.pos4_ver[0]=player2.wall[10].pos4_ver[0];
            player2.wall.pos4_ver[1]=player2.wall[i-1].pos4_ver[1]+wallinc;
            player2.wall.dead=false;
            player2.wall.health=100;
        }
        
        if(i>20)
        {
            player2.wall.pos_ver[0]=player2.wall[i-1].pos_ver[0]+wallinc;
            player2.wall.pos_ver[1]=player2.wall[20].pos_ver[1];
            player2.wall.pos2_ver[0]=player2.wall[i-1].pos2_ver[0]+wallinc;
            player2.wall.pos2_ver[1]=player2.wall[20].pos2_ver[1];
            player2.wall.pos3_ver[0]=player2.wall[i-1].pos3_ver[0]+wallinc;
            player2.wall.pos3_ver[1]=player2.wall[20].pos3_ver[1];
            player2.wall.pos4_ver[0]=player2.wall[i-1].pos4_ver[0]+wallinc;
            player2.wall.pos4_ver[1]=player2.wall[20].pos4_ver[1];
            player2.wall.dead=false;
            player2.wall.health=100;
        }
    }    


This next part is where the wall sections are actually drawn. It is in a seperate function.
for(i=0;i<31;i++)
       {
      
            
          //first base's wall
          glColor3f(1.0,0.2,0.0);
          glBegin(GL_QUADS);
          glTexCoord2f(0.0,0.0);glVertex2fv(player1.wall.pos_ver); 
          glTexCoord2f(1.0,0.0);glVertex2fv(player1.wall.pos2_ver); 
          glTexCoord2f(1.0,1.0);glVertex2fv(player1.wall.pos3_ver); 
          glTexCoord2f(0.0,1.0);glVertex2fv(player1.wall.pos4_ver);
          glEnd();

          //second base's wall
          glBegin(GL_QUADS);
          glTexCoord2f(0.0,0.0);glVertex2fv(player2.wall.pos_ver); 
          glTexCoord2f(1.0,0.0);glVertex2fv(player2.wall.pos2_ver); 
          glTexCoord2f(1.0,1.0);glVertex2fv(player2.wall.pos3_ver); 
          glTexCoord2f(0.0,1.0);glVertex2fv(player2.wall.pos4_ver);
          glEnd();
          
      }    


I wish I had hosting so I could post a picture of the problem but I don't. If you need the picture please PM me or IM me my sn is Pluto035. Thanks in advance. [Edited by - PlutoWarrior on July 22, 2005 4:46:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by PlutoWarrior
I wish I had hosting so I could post a picture of the problem but I don't. If you need the picture please PM me or IM me my sn is Pluto035. Thanks in advance.


Sorry I'm not able to answer your question, but for the imagehosting part why not use http://www.imageshack.us/

If it helps explain the problem I've found illustrations and pictures to be of a great help :)

Share this post


Link to post
Share on other sites
Looks like you are giving OpenGL invalid values. Maybe you are overrunning the end of the array which holds the vertex positions.
Step through the rendering loop with the debugger, maybe you can see some odd values.
If the value is NaN, you could find it by:
assert(value == value);
(NaN is not equal to any number, not even itself)


Share this post


Link to post
Share on other sites
I think I was overrunning them somewhere... not quite sure where though. The problem suddenly stopped after I added a few more textures to my game. Thanks for the reply.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!