简体   繁体   English

使用opengl的简单glfw绘制点什么都不显示

[英]Simple glfw draw point with opengl shows nothing

I can see the screen has been cleared to red,but no point in the center of the screen,any way here is the full code: 我可以看到屏幕已被清除为红色,但是屏幕中央没有任何一点,这是完整的代码:

#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();
}

compiled using: 编译使用:

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.

if I compile it use gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 ); 如果我编译它使用gluPerspective( 65.0, (double)1024/(double)768, 1.0, 60.0 ); still the same,no point in the center of the screen,I use this makefile to compile it: 还是一样,屏幕中央没有一点,我用这个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

You need a glLoadIdentity() before glOrtho() . 您需要在glLoadIdentity()之前添加glOrtho()

glOrtho() doesn't set the current matrix, it multiplies by it. glOrtho()不会设置当前矩阵,而是与其相乘 So set the current matrix to a known-good value (the identity matrix, via glLoadIdentity() ) before calling it. 因此,在调用它之前,将当前矩阵设置为一个已知良好的值(通过glLoadIdentity()的恒等矩阵glLoadIdentity()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM