Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Problem: when i run this program, i just got a white window.

  1. #1
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    2

    Problem: when i run this program, i just got a white window.

    HI,
    I got a program from <opengl programming guide>, but when i run the program, there is nothing but a white window.
    Any of your suggestion will be appreciated.

    The codes as follow:


    #include <Windows.h>
    #include <stdio.h>
    #include <GL/glew.h>
    #include <gl/glut.h>


    #pragma comment(lib, "glew32.lib")


    #define VERTICES 0
    #define INDICES 1
    #define NUM_BUFFERS 2
    #define BUFFER_OFFSET(bytes) ((GLubyte*)NULL+(bytes))

    using namespace std;


    void init(){

    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);

    GLuint buffers[NUM_BUFFERS];

    GLfloat vertices[][3] = {
    {-50.0, -50.0, -50.0},
    {50.0, -50.0, -50.0},
    {50.0, 50.0, -50.0},
    {-50.0, 50.0, -50.0},
    {-50.0, -50.0, 50.0},
    {50.0, -50.0, 50.0},
    {50.0, 50.0, 50.0},
    {-50.0, 50.0, 50.0}
    };
    GLubyte indices[][4] = {
    {0, 1, 2, 3},
    {4, 7, 6, 5},
    {0, 4, 5, 1},
    {3, 2, 6, 7},
    {0, 3, 7, 4},
    {1, 5, 6, 2}
    };

    glGenBuffers(NUM_BUFFERS, buffers);
    glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
    glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
    glEnableClientState(GL_VERTEX_ARRAY);

    glBindBuffer(GL_ARRAY_BUFFER, buffers[INDICES]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW );
    glEnableClientState(GL_INDEX_ARRAY);
    }

    void display(){

    glClear(GL_COLOR_BUFFER_BIT);//|GL_DEPTH_BUFFER_BIT);
    glColor3f(0, 0, 1);
    glDrawElements(GL_QUADS, 24, GL_FLOAT, BUFFER_OFFSET(0));

    }

    void reshape(int w, int h){
    glViewport(-100, -100, (GLsizei)w, (GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(-100, (GLdouble)(w-100), -100, (GLdouble)(h-100));
    }

    int main(int argc, char ** argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(800, 600);
    glutInitWindowPosition(100,100);
    glutCreateWindow(argv[0]);
    glewInit();
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
    }

  2. #2
    Newbie Newbie
    Join Date
    Nov 2013
    Posts
    2
    suddenly, i found that i have used a gluortho2D() to display a 3d mesh....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •