C++ OpenGL Drawing Grid (help)

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 2896 Views - Last Post: 04 May 2013 - 04:10 PM Rate Topic: ***** 1 Votes

#16 TurkogluTurk  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 45
  • Joined: 03-April 12

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 03:14 PM

View Post#define, on 04 May 2013 - 02:05 PM, said:

You are confusing the class member names with the parameter names, add m_ before the member variables to differentiate them. Do you need to inherit from Shape?

#ifndef	Grid_h
#define Grid_h 

#include "Shape.h" 

class Grid : public Shape
{ 
  public: 
  Grid(); 
  Grid(int cizgiSayisi,int cizgiArasiMesafe); 
  void Draw(); 

  int m_distanceBetweenLines; 
  int m_numberOfLines; 
}; 

#endif 




In the implementation file the for loops should be in Draw.

#include "Grid.h"
#include <GL/freeglut.h>

Grid:: Grid()
{
  m_numberOfLines = 0;
  m_distanceBetweenLines = 0;
}

Grid:: Grid(int numberOfLines , int distanceBetweenLines )
{
  //cizimSekli       = GL_LINES; //drawing way 
  //cizgisayisi             = 50;   //number of Lines
  //renk        = Renk(0.0f, 1.0f, 0.0f); //Colour
  //m_distanceBetweenLines            = 20;
}


void Grid::Draw()
{
  //glTranslatef(0.0f, 0.0f, -5.0f);

  // test print one line 
  glBegin(GL_LINES);
    glColor3f ( 0.0,  1.0, 0.0);
    glVertex2f(-1.0, -1.0);
    glVertex2f( 0.0,  0.0);
  glEnd();

  /*
  for(int x = 0; x < cizgisayisi; x++){
    glBegin(GL_LINES);
    glVertex2f(x,0);
    glVertex2f(0,x);
    glEnd();
  };
  for(int y = 0; y < cizgisayisi; y++){
    glBegin(GL_LINES);
    glVertex2f(y,0);
    glVertex2f(0,y);
    glEnd();
  };
  */
}




Are you able to create a Grid object and draw it?

Yes i do. I created an object in main.cpp file. And used there for loops to draw the grid. Like that :
grid g;
for(int x=1; x<50; x++)
g.Draw();
for(int y=1; y<50; y++)
g.Draw();

But when i use that it's not drawing even the snake which was already created a bit before. There's also a drawing function in shape.cpp. This may cause the matter.
Was This Post Helpful? 0
  • +
  • -

#17 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1312
  • View blog
  • Posts: 4,512
  • Joined: 19-February 09

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 03:45 PM

Your Grid class should draw the grid so there is no need to use the for loops in main.cpp.

All you need is :

Grid g;

g.Draw();




I don't know why the snake is not being drawn.
Draw doesn't draw to the screen but to the model in memory, so both the grid and the snake are drawn to memory, then SwapBuffers will draw the model to the screen.
Was This Post Helpful? 0
  • +
  • -

#18 TurkogluTurk  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 45
  • Joined: 03-April 12

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 04:10 PM

View Post#define, on 04 May 2013 - 03:45 PM, said:

Your Grid class should draw the grid so there is no need to use the for loops in main.cpp.

All you need is :

Grid g;

g.Draw();




I don't know why the snake is not being drawn.
Draw doesn't draw to the screen but to the model in memory, so both the grid and the snake are drawn to memory, then SwapBuffers will draw the model to the screen.


I'm trying to fix the problem. I'll disturb you for another matter. Thank you sir :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2