2016-05-30 117 views
0

我不知道如何解決這個問題,我想用這個函數來製作一個軟渲染引擎來學習3D管道。 它看起來像你的文章主要是代碼;請添加更多的細節。由glfw繪製的渲染圖只渲染四分之一屏幕。緩衝區使用屏幕寬度*高度

Current situation

這是代碼:

#define GLFW_INCLUDE_GLU 
#include <GLFW/glfw3.h> 

int main(int argc, const char * argv[]) { 
    if(!glfwInit()){ //init error 
     return -1; 
    } 

    int width = 200; //screen width 
    int height = 200; //screen height 

    GLFWwindow* window = glfwCreateWindow(width, height, "Hello OpenGL", NULL, NULL); //create window 

    if(!window){  //create window fail 
     glfwTerminate(); 
     return -1; 
    } 

    u_char* pixels = new unsigned char[width * height * 4]; //buffer 
    uint index; //temp 

    //set pixel 
    for (int count_a = 0; count_a < width; count_a++) { 
     for (int count_b = 0; count_b < height; count_b++) { 
      index = count_b * width + count_a; 

      pixels[index * 4 + 0] = 255; //red pixel 
      pixels[index * 4 + 1] = 0;  //green 
      pixels[index * 4 + 2] = 0;  //blue 
      pixels[index * 4 + 3] = 255; //alpha 
     } 
    } 

    glfwMakeContextCurrent(window); 
    while (!glfwWindowShouldClose(window)) { //close window 
     glClearColor(1.0, 1.0, 1.0, 1.0); //clear screen by white pixel 
     glClear(GL_COLOR_BUFFER_BIT); 
     glRasterPos2f(-1, -1); //set origin to screen bottom left 
     //glPixelZoom(2, 2); //if i use this function. renderer is right. 
     glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); //draw pixel 

     glfwSwapBuffers(window); //swap buffer 
    } 
    glfwTerminate(); 
    return 0; 
} 
+0

您使用的是什麼版本的OpenGL? – Exide

+1

嘗試調用glLoadIdentity。而不是glRasterPos,請指定您自己的投影矩陣 – RecursiveExceptionException

回答

0

這是here重複的問題。您需要將幀緩衝區大小傳遞給您的glViewport調用。請參閱鏈接瞭解更多詳情。