A
A
Avery0072014-04-27 15:58:41
C++ / C#
Avery007, 2014-04-27 15:58:41

Why does my OpenGL work incorrectly or not work at all?

I'm learning OpenGL, found some of the headers in C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl , downloaded some.
But the examples from the SuperBook either do not work, or draw some kind of heresy (the example should display points in the form of a spiral, only two are displayed), although I rewrite everything exactly.
From the examples from the Internet, the same is true. I have Visual Studio Express 2012.
Here is the code for the last example I rewrote:

The code
#include "stdafx.h"
#include "glut.h"
#include "GL.h"
#include "GLAux.h" 
#include "GLU.H"

void DisplayFunc();
void reshape(GLsizei w, GLsizei h);
void reshape(int w, int h)
{
    if (h = 0) h=1;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
    {
      gluOrtho2D(0.0, 30.0 * (float)w / (float)h, 0.0, 30.0);
    }
    else
    {
      gluOrtho2D(0.0, 30.0 * (float)w / (float)h, 0.0, 30.0);
    }
    glClearColor(0.0, 0.0, 0.0, 0.0);
    
    glViewport(0, 0, w, h);
 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
}
 
void DisplayFunc()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor3f(1.0f, 0.0f, 0.0f);
  glRectf(0.0f, 0.0f, 25.0f, 25.0f);
  glFlush();
}
 
int main (int argc, char * argv[])
{
        glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA | GLUT_DEPTH);
        glutInitWindowSize(640, 480);
        glutCreateWindow("OpenGL lesson 1");   
        glutReshapeFunc(reshape);
        glutDisplayFunc(DisplayFunc);
    glutMainLoop();
        return 0;
}

Maybe I'm doing something wrong?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Ivan Pavlenko, 2014-07-27
@MrGobus

When creating a window, you specify GLUT_DOUBLE, which means that the double buffering mode will be enabled, that is, the picture is drawn in the machine's memory and then displayed on the screen in order to avoid flickering and visible drawing. In order for the image to appear on the screen when the frame is completed, you need to call the frame change function, in the case of glut, it seemed to be glutSwapBuffers.
In your example, this is after glFlush();

V
Vadim Gush, 2014-04-27
@VadimGu

Maybe it's because of the libraries, if you completely rewrote the code from the book, then theoretically there can be no problems.

N
nesterione, 2014-04-27
@nesterione

My problems arose only because of not installed drivers. True, on win I used gcc (mingw). But there shouldn't be a difference. You can try using another opengl implementation like mesa 3d. (You tell the compiler the path to the opengl32 and glu32 dlls? It’s just that many friends forgot, and the code didn’t compile. I also recommend nehe.gamedev.net , there are good lectures, with code examples, with compilation of which there are no problems (checked)

P
pigah, 2014-04-27
@pigah

Perhaps the examples are old, better use this book

A
afiskon, 2014-04-28
@afiskon

Perhaps the vidyuhi manufacturer made crooked drivers. I heard it happens quite often. Try running the examples on another computer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question