C语言 带有 opengl 的简单 glfw 绘制点不显示任何内容



>我可以看到屏幕已被清除为红色,但屏幕中央没有点,无论如何这里是完整的代码:

#include "GL/glfw.h"
void render_loop()
{
    glClearColor ( .7, .1, .1, 1.0f );
    glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glViewport(0,0,1024,768);
    glMatrixMode(GL_PROJECTION);
    //gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 );
    glOrtho(0,1024,768,0,100,-100);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPointSize(10);
    glBegin(GL_POINTS);
    glColor4f(1,1,1,1);
    glVertex3f(512,384,0);
    glEnd();
    glfwSwapBuffers();
}
int main ( int argc, char* argv[] )
{
    //init glfw
    glfwInit();
    glfwOpenWindow ( 1024, 768, 8, 8, 8, 8, 24, 0, GLFW_WINDOW );
    do {
        render_loop();
    } while ( glfwGetWindowParam ( GLFW_OPENED ) );
    glfwTerminate();
}

编译使用:

john@Linux:~> gcc --version
gcc (SUSE Linux) 4.7.1 20120723 [gcc-4_7-branch revision 189773]
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

如果我编译它使用gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 );仍然是一样的,屏幕中央没有点,我用这个makefile来编译它:

#makefile for example1 on linux
CC=gcc  -std=c99  -Wno-unused-function -Wno-unused-variable

SRC=
a.c 
OBJS=$(SRC:.c=.o)
NAME=testglpoints
CFLAGS =   -Wall $(INCLUDE) 
LFLAGS =
-lGL 
-lglut 
-lGLU 
-lGLEW 
-ldl 
-lpthread 
-lm 
-lglfw

all: debug
debug:override CFLAGS = -g3 -O0 -Wall 
debug:$(OBJS)
    $(CC)  $(CFLAGS) $(LFLAGS)   $(SRC)    -o $(NAME) 
clean:
    @rm -f *.o

您需要一个glLoadIdentity()才能glOrtho()

glOrtho()设置当前矩阵,而是乘它。 因此,在调用当前矩阵之前,将当前矩阵设置为已知良好的值(单位矩阵,通过 glLoadIdentity() )。

最新更新