OpenGL square not showing up..

This is a discussion on OpenGL square not showing up.. within the Game Programming forums, part of the General Programming Boards category; Hi, so im new to graphics programming and decided to try openGL (I'm planning on making a 2D game in ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    106

    OpenGL square not showing up..

    Hi, so im new to graphics programming and decided to try openGL (I'm planning on making a 2D game in it at first, possibly pacman). And I'm having trouble getting it to draw shapes on the screen.

    Code:
    #include "glut.h"
    
    #define WIDTH 350
    #define HEIGHT 500
    
    void display();
    
    void display()
    {
    	glClearColor(1.0, 0.0, 0.0, 1.0);
    	glClear(GL_COLOR_BUFFER_BIT);
    	glLoadIdentity();
    	glTranslatef(0.0, 0.0, -5.0);
    	glBegin(GL_QUADS);
    	glVertex3f(-1.0f, -1.0f, 0.0f);
    	glVertex3f(-1.0f, 1.0f, 0.0f);
    	glVertex3f(1.0f, 1.0f, 0.0f);
    	glVertex3f(1.0f, -1.0f, 0.0f);
    	glEnd();
    
    	glFlush();
    }
    
    int main(int argc, char **argv)
    {
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_SINGLE);
    	glutInitWindowSize(WIDTH, HEIGHT);
    	glutInitWindowPosition(100, 100);
    	glutCreateWindow("PacMan");
    	glutDisplayFunc(display);
    	glutMainLoop();
    }

    also once i get to the point of coding a pacman game.. would the best method be to use and array to represent a tile like system to draw the game boards, and to be used with the ghost AI

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Just venturing a guess here: replace GLUT_SINGLE by GLUT_DOUBLE and replace glFlush() by glutSwapBuffers().
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    106
    The problem still persists. Its just a blank red screen. I'm wondering if its the xyz positions? I'm just a newb at this graphics stuff though

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Have you read this tutorial series?
    NeHe Productions: OpenGL Lesson #02
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    106
    I went with a different tutorial series, because of it using glut to create the window instead of the WINAPI. the link to the tutorial Swiftless OpenGL Tutorials | Swiftless Tutorials I created this set of code by myself, and when it didnt work i reffered back to the tutorial code but im failing to see whats wrong(evidently something is)

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Off-hand, maybe
    a) it's very small (like 1x1 pixel)
    b) it's also coloured red
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    You haven't set-up your projection matrix, as a result, when you translate your geometry beyond -1.0 in z-direction, it is outside your far clipping plane, i.e. you can't see it. You should set-up your projection matrix. Refer to the GLUT code for 'Lesson 02: Your first polygon' in the NeHe tutorial database.
    Long story short: you have to register a callback through glutReshapeFunc, which gets called eveytime your window changes dimensions (and also when it is first created). You switch to the projection matrix (glMatrixMode(GL_PROJECTION)), and set-up the desired projection transforms (a call to gluPerspective usually does the trick).

    In any case, I would recommend you either follow through NeHe's tutorials (which also include code for GLUT), or download a (freely available) copy of the (outdated, but still useful for beginners, version) of the OpenGL redbook.

    EDIT: opengl.org seems to be unreachable at the moment...
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    106
    The projection matrix was the problem.. I feel dumb because I tried to avoid the reshape function for this but as I found out it was definately needed. Thanks for the help guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loop seg error
    By Zishaan in forum Game Programming
    Replies: 2
    Last Post: 03-28-2007, 01:27 PM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. Help with my draughts game
    By Zishaan in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 07:33 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 06:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21