Results 1 to 3 of 3

Thread: Drawing an [10][10] Field with Cubes

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2013
    Posts
    6

    Drawing an [10][10] Field with Cubes

    Hello,
    i'm programming battleship for Opengl.

    I have already the game logic and it works fine.

    Now im programming the graphics and i want to draw a field 10x10.

    I do this with the drawGameField();

    Problem that i don't understand:

    Line 71: why i must translate with this strange numbers? isnt there a formula ?

    Line 98: again, why i must devide with 2 ?

    Line 101: why *2 ?

    I dont understand it.
    Later i want to navigate the fields by pressing keys, and i dont know if it will really work with these numbers.

    Next Problem is, that i got 10 fields but the lines are overlapping.

    Field looks like this:


    Thanks



  2. #2
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Drawing an [10][10] Field with Cubes

    Rather than asking us, you should answer these yourself because it is you who has made those decisions.
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2012
    Location
    London
    Posts
    2

    Re: Drawing an [10][10] Field with Cubes

    Presumably you were given the code as an assignment for a lab or you are using source code. Can you post the code instead of attaching it? It would make it much easier to see what is happening.

    I'm assuming your 2nd line number is actually 116, not 98.

    Code :
    116: glTranslatef((gamewidth*i)/2,0,0);

    Since your 'reshape' function sets the glMatrixMode to GL_MODELVIEW, all your calls to glTranslate are in fact telling the display where to draw.

    I'd take another look at your screen size constant definitions:

    Code :
    #define gamewidth 0.7
    #define linehigh 4
    #define linewidth 0.05

    Assuming your game is in landscape mode, it may be better to redefine your constants similar to this:

    Code :
    #define gamewidth 1.3
    #define gameheight 1
    #define linehigh 4
    #define linewidth 0.05

    For some reason you are scaling a cube into a line and using that to draw the grid. It would be much easier to use GL_LINES.

    Draw horizontal:

    Code :
    glBegin(GL_LINES);
    glVertex3f(0.0f, i*16, 0.0f); // origin of the line
    glVertex3f(640.0f, i*16, 0.0f); // ending point of the line
    glEnd( );

    Draw vertical:

    Code :
    glBegin(GL_LINES);
    glVertex3f(i*16, 0.0f, 0.0f); // origin of the line
    glVertex3f(i*16, 480.0f, 0.0f); // ending point of the line
    glEnd( );

    Assuming your screen is 640x480.

    Who gave you the misleading idea to draw lines with an elongated cube? Very very bad practise If in doubt, search online for 'drawing line primitives in openGL'. Once you have got the grid drawn then worry about moving objects etc.

Similar Threads

  1. I need help drawing some cubes
    By Areinn in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-08-2013, 08:50 PM
  2. loop drawing cubes
    By Kabaj in forum OpenGL: General
    Replies: 1
    Last Post: 08-23-2012, 10:54 AM
  3. Drawing millions cubes
    By backus in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 10-24-2011, 11:42 AM
  4. Drawing many cubes
    By metalac in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-18-2010, 09:40 AM
  5. Problem with drawing Twisted Cubes
    By Tom Thorp in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-12-2008, 09:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean