Skip to main content
added 72 characters in body
Source Link
gotanod
  • 341
  • 2
  • 7
void SetLocationE()
{
    glLoadIdentity();
    glTranslatef(-11.5f, -8.125f, .0f);
}  

void ScreenBuffer::drawQuad(int column, int row, float r, float g, float b) 
{
    // Draw quad
    SetLocationE();
    float x = jcolumn * 23.0 / 40.0;
    float y = irow * 16.25 / 20.0;
    glTranslatef(x, y, zet);
    glBegin(GL_QUADS);
    //painting
    glColor3f(r, g, b);            
    //drawing  TOP RIGHT -> TOP LEFT
    //         -> BOTTOM LEFT -> BOTTOM RIGHT
    glVertex3f(0.15f, 0.15f, .0f);  //tr
    glVertex3f(-0.15f, 0.15f, .0f);  //tl    
    glVertex3f(-0.15f, -0.15f, .0f);  //bl    
    glVertex3f(0.15f, -0.15f, .0f);  //br
    glEnd();
}

void ScreenBuffer::RenderToScreen(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /* DRAW */
    for (int i = 0; i < 20; i++)  // Y [0-20]
    {
        for (int j = 0; j < 40; j++)  // X [0-40]
        {
            // select color            
            if (MAP[i][j] == 'x') { 
                 drawQuad(j, i, 0.0f, 0.0f, 0.0f); 
            }
            else if (MAP[i][j] == '0') 
            { 
                drawQuad(j, i, 0.0f, 0.3f, 0.1f); 
            }
            else if (MAP[i][j] == 'o') 
            { 
                drawQuad(j, i, 0.0f, 0.7f, 0.2f); 
            }
        }
    }
}
void SetLocationE()
{
    glLoadIdentity();
    glTranslatef(-11.5f, -8.125f, .0f);
}  

void drawQuad(float r, float g, float b) 
{
    // Draw quad
    SetLocationE();
    float x = j * 23.0 / 40.0;
    float y = i * 16.25 / 20.0;
    glTranslatef(x, y, zet);
    glBegin(GL_QUADS);
    //painting
    glColor3f(r, g, b);            
    //drawing  TOP RIGHT -> TOP LEFT
    //         -> BOTTOM LEFT -> BOTTOM RIGHT
    glVertex3f(0.15f, 0.15f, .0f);  //tr
    glVertex3f(-0.15f, 0.15f, .0f);  //tl    
    glVertex3f(-0.15f, -0.15f, .0f);  //bl    
    glVertex3f(0.15f, -0.15f, .0f);  //br
    glEnd();
}

void ScreenBuffer::RenderToScreen(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /* DRAW */
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < 40; j++)
        {
            // select color            
            if (MAP[i][j] == 'x') { 
                 drawQuad(0.0f, 0.0f, 0.0f); 
            }
            else if (MAP[i][j] == '0') 
            { 
                drawQuad(0.0f, 0.3f, 0.1f); 
            }
            else if (MAP[i][j] == 'o') 
            { 
                drawQuad(0.0f, 0.7f, 0.2f); 
            }
        }
    }
}
void SetLocationE()
{
    glLoadIdentity();
    glTranslatef(-11.5f, -8.125f, .0f);
}  

void ScreenBuffer::drawQuad(int column, int row, float r, float g, float b) 
{
    // Draw quad
    SetLocationE();
    float x = column * 23.0 / 40.0;
    float y = row * 16.25 / 20.0;
    glTranslatef(x, y, zet);
    glBegin(GL_QUADS);
    //painting
    glColor3f(r, g, b);            
    //drawing  TOP RIGHT -> TOP LEFT
    //         -> BOTTOM LEFT -> BOTTOM RIGHT
    glVertex3f(0.15f, 0.15f, .0f);  //tr
    glVertex3f(-0.15f, 0.15f, .0f);  //tl    
    glVertex3f(-0.15f, -0.15f, .0f);  //bl    
    glVertex3f(0.15f, -0.15f, .0f);  //br
    glEnd();
}

void ScreenBuffer::RenderToScreen(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /* DRAW */
    for (int i = 0; i < 20; i++)  // Y [0-20]
    {
        for (int j = 0; j < 40; j++)  // X [0-40]
        {
            // select color            
            if (MAP[i][j] == 'x') { 
                 drawQuad(j, i, 0.0f, 0.0f, 0.0f); 
            }
            else if (MAP[i][j] == '0') 
            { 
                drawQuad(j, i, 0.0f, 0.3f, 0.1f); 
            }
            else if (MAP[i][j] == 'o') 
            { 
                drawQuad(j, i, 0.0f, 0.7f, 0.2f); 
            }
        }
    }
}
deleted 1 character in body
Source Link
gotanod
  • 341
  • 2
  • 7

I think you have a typo in these lines (BAIT and TAILS), it should be divided by 20 instead of 40 (HEAD divides y by 20). That explains why they are showedshown only on the bottom half of the screen.

I think you have a typo in these lines (BAIT and TAILS), it should be divided by 20 instead of 40 (HEAD divides y by 20). That explains why they are showed only on the bottom half of the screen.

I think you have a typo in these lines (BAIT and TAILS), it should be divided by 20 instead of 40 (HEAD divides y by 20). That explains why they are shown only on the bottom half of the screen.

added 1498 characters in body
Source Link
gotanod
  • 341
  • 2
  • 7

Also you can extract the drawing of the quad to another function, because it is the same code.

void SetLocationE()
{
    glLoadIdentity();
    glTranslatef(-11.5f, -8.125f, .0f);
}  

void drawQuad(float r, float g, float b) 
{
    // Draw quad
    SetLocationE();
    float x = j * 23.0 / 40.0;
    float y = i * 16.25 / 20.0;
    glTranslatef(x, y, zet);
    glBegin(GL_QUADS);
    //painting
    glColor3f(r, g, b);            
    //drawing  TOP RIGHT -> TOP LEFT
    //         -> BOTTOM LEFT -> BOTTOM RIGHT
    glVertex3f(0.15f, 0.15f, .0f);  //tr
    glVertex3f(-0.15f, 0.15f, .0f);  //tl    
    glVertex3f(-0.15f, -0.15f, .0f);  //bl    
    glVertex3f(0.15f, -0.15f, .0f);  //br
    glEnd();
}

void ScreenBuffer::RenderToScreen(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /* DRAW */
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < 40; j++)
        {
            // select color            
            if (MAP[i][j] == 'x') { 
                 drawQuad(0.0f, 0.0f, 0.0f); 
            }
            else if (MAP[i][j] == '0') 
            { 
                drawQuad(0.0f, 0.3f, 0.1f); 
            }
            else if (MAP[i][j] == 'o') 
            { 
                drawQuad(0.0f, 0.7f, 0.2f); 
            }
        }
    }
}

Also you can extract the drawing of the quad to another function, because it is the same code.

void SetLocationE()
{
    glLoadIdentity();
    glTranslatef(-11.5f, -8.125f, .0f);
}  

void drawQuad(float r, float g, float b) 
{
    // Draw quad
    SetLocationE();
    float x = j * 23.0 / 40.0;
    float y = i * 16.25 / 20.0;
    glTranslatef(x, y, zet);
    glBegin(GL_QUADS);
    //painting
    glColor3f(r, g, b);            
    //drawing  TOP RIGHT -> TOP LEFT
    //         -> BOTTOM LEFT -> BOTTOM RIGHT
    glVertex3f(0.15f, 0.15f, .0f);  //tr
    glVertex3f(-0.15f, 0.15f, .0f);  //tl    
    glVertex3f(-0.15f, -0.15f, .0f);  //bl    
    glVertex3f(0.15f, -0.15f, .0f);  //br
    glEnd();
}

void ScreenBuffer::RenderToScreen(GLvoid)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    /* DRAW */
    for (int i = 0; i < 20; i++)
    {
        for (int j = 0; j < 40; j++)
        {
            // select color            
            if (MAP[i][j] == 'x') { 
                 drawQuad(0.0f, 0.0f, 0.0f); 
            }
            else if (MAP[i][j] == '0') 
            { 
                drawQuad(0.0f, 0.3f, 0.1f); 
            }
            else if (MAP[i][j] == 'o') 
            { 
                drawQuad(0.0f, 0.7f, 0.2f); 
            }
        }
    }
}
Source Link
gotanod
  • 341
  • 2
  • 7
Loading