C++ OpenGL Drawing Grid (help)

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 TurkogluTurk  Icon User is offline

  • New D.I.C Head

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

C++ OpenGL Drawing Grid (help)

Posted 03 May 2013 - 03:17 PM

Hi
I have a header file like that. I'm willing to create a grid. By using OpenGl and C++. The problem is in there cpp file. I can't excatly draw. Hope you can help it.


#ifndef Grid_h
#define Grid_h
#include "Shape.h"

class Grid:public Shape
{
public:
Grid();
Grid(int cizgiSayisi,int cizgiArasiMesafe);
void Draw();
int distanceBetweenLines;
int numberOfLines;
};
#endif



#include "Grid.h"

#include <GL/freeglut.h>

Grid:: Grid()

{
    numberOfLines = 0.0f;
    distanceBetweenLines = 0.0f;
}
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
    distanceBetweenLines            = 20;
   
    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();
    };     
}


This post has been edited by TurkogluTurk: 03 May 2013 - 03:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ OpenGL Drawing Grid (help)

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: C++ OpenGL Drawing Grid (help)

Posted 03 May 2013 - 03:48 PM

Is this your code?
Was This Post Helpful? 0
  • +
  • -

#3 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 03 May 2013 - 04:00 PM

View PostButchDean, on 03 May 2013 - 03:48 PM, said:

Is this your code?

Only the loop part is not mine.

The 9th line of the first episode [Grid(int cizgiSayisi,int cizgiArasiMesafe);] should be Grid(int numberOfLines,int distanceBetweenLines );

This post has been edited by TurkogluTurk: 03 May 2013 - 04:04 PM

Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: C++ OpenGL Drawing Grid (help)

Posted 03 May 2013 - 05:06 PM

Try writing your own code from scratch, you won't understand by copying.
Was This Post Helpful? 0
  • +
  • -

#5 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 - 01:40 AM

Up
Was This Post Helpful? 0
  • +
  • -

#6 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 01:45 AM

View PostTurkogluTurk, on 04 May 2013 - 07:40 PM, said:

Up


Down.

What is Up, supposed to mean?

I took the liberty of finding you an article on this exact same problem, read it and make sure you understand the code:
A Grid in OpenGL

Hope it helps

Aaron1178
Was This Post Helpful? 0
  • +
  • -

#7 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 - 02:55 AM

View Postaaron1178, on 04 May 2013 - 01:45 AM, said:

View PostTurkogluTurk, on 04 May 2013 - 07:40 PM, said:

Up


Down.

What is Up, supposed to mean?

I took the liberty of finding you an article on this exact same problem, read it and make sure you understand the code:
A Grid in OpenGL

Hope it helps

Aaron1178


Thanks. I've seen this article but it unfortunately couldn't exactly help me.
Was This Post Helpful? 0
  • +
  • -

#8 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 03:17 AM

So you want us to give you the Draw() method code for you?
Was This Post Helpful? 0
  • +
  • -

#9 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:35 AM

View Postaaron1178, on 04 May 2013 - 03:17 AM, said:

So you want us to give you the Draw() method code for you?

I just want to know what am i doing wrong and a idea for fixing it.
Was This Post Helpful? 0
  • +
  • -

#10 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 03:53 AM

According to the article I linked above, it gives you the solution to your needs:

Quote

glBegin(GL_LINES);
for(int i = 0; i <= 100; i += 10)
{
    glVertex3f((float)i, 0.0f, 0.0f);
    glVertex3f((float)i, 100.0f, 0.0f);
    glVertex3f(0.0f, (float)i, 0.0f);
    glVertex3f(100.0f, (float)i, 0.0f)
}
glEnd();



This will draw a grid, 100 x 100, if I'm not mistaking. Just do some research and extrapolate a solution using the above quote.

Hope it helps

Aaron1178
Was This Post Helpful? 0
  • +
  • -

#11 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:01 AM

View Postaaron1178, on 04 May 2013 - 03:53 AM, said:

According to the article I linked above, it gives you the solution to your needs:

Quote

glBegin(GL_LINES);
for(int i = 0; i <= 100; i += 10)
{
    glVertex3f((float)i, 0.0f, 0.0f);
    glVertex3f((float)i, 100.0f, 0.0f);
    glVertex3f(0.0f, (float)i, 0.0f);
    glVertex3f(100.0f, (float)i, 0.0f)
}
glEnd();



This will draw a grid, 100 x 100, if I'm not mistaking. Just do some research and extrapolate a solution using the above quote.

Hope it helps

Aaron1178


It shouldn't be 3d.So glVertex2f(...,...) how should i fill in the blanks ?
Was This Post Helpful? 0
  • +
  • -

#12 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 04:08 AM

That's where I'll let you do some research, just google OpenGL glVertex2f.
Was This Post Helpful? 0
  • +
  • -

#13 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 - 08:36 AM

I guess i need someone who knows Opengl.
Was This Post Helpful? 0
  • +
  • -

#14 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 11:43 AM

I know OpenGL, my first ever game was written using it and it was a 3D game. You need to be bothered to do research, PMs and bumping your posts isn't going to work.

One more bump and I'll close this topic.
Was This Post Helpful? 0
  • +
  • -

#15 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1327
  • View blog
  • Posts: 4,554
  • Joined: 19-February 09

Re: C++ OpenGL Drawing Grid (help)

Posted 04 May 2013 - 02:05 PM

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?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2