将属性传递给OpenGL顶点着色器奇怪 [英] Passing attributes to OpenGL vertex shader acts strangely

查看:402
本文介绍了将属性传递给OpenGL顶点着色器奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:



结果1:我将顶点属性传递给着色器,程序运行

结果2:我将帧速率设为60然后做同样的事情。程序运行良好,但是当我尝试在同一个运行时传递不同的顶点属性值时,它不会更新几何(只有第一个顶点属性传递成功)。



我使用OpenGL版本3.1与GLSL 140.(我的显卡/驱动程序将支持最高的)



我试过:



互联网浏览和阅读教程。因为我不太了解OpenGL,但我认为问题是我只是不知道要搜索什么。



注意:如果我有一些坏的OpenGL代码



opengl2_vert.glsl

/ p>

  #version 140 

in vec4 offset;

void main(void)
{
//声明一个硬编码的位置数组
vec4 vertices [3] = vec4 [3] ,-0.25,0.5,1.0),
vec4(-0.25,-0.25,0.5,1.0),
vec4(0.25,0.25,0.5,1.0));
//使用gl_VertexID索引到数组中
gl_Position = vertices [gl_VertexID] - offset;
}

Game.cpp

  #includeGame.h


void Game :: init()
{
GLuint vertex_shader = getIO ().loadShader(opengl2_vert.glsl,ShaderType :: VERTEX);
GLuint fragment_shader = getIO()。loadShader(opengl2_frag.glsl,ShaderType :: FRAGMENT);

//创建程序,为它添加着色器,并链接它
program = glCreateProgram();
glAttachShader(program,vertex_shader);
glAttachShader(program,fragment_shader);
glLinkProgram(program);

GLint isLinked = GL_FALSE;
glGetProgramiv(program,GL_LINK_STATUS,& isLinked);

//记录
GLint maxLength = 255;
GLint rLength = 0;
GLchar * err = new char [maxLength];

//顶点着色器
glGetShaderInfoLog(vertex_shader,maxLength,& rLength,err);
DEBUGSTR((char *)err);

//片段着色器
glGetShaderInfoLog(vertex_shader,maxLength,& rLength,err);
DEBUGSTR((char *)err);

//程序
glGetProgramInfoLog(vertex_shader,maxLength,& rLength,err);
DEBUGSTR((char *)err);

delete [] err;
ASSERT(isLinked == GL_TRUE);



//当程序有它们时删除着色器
glDeleteShader(vertex_shader);
glDeleteShader(fragment_ shader);

glUseProgram(program);

// VAO
glGenVertexArrays(1,& vertex_array_object); // Creates a VAO
glBindVertexArray(vertex_array_object); //将VAO附加到渲染上下文

}

void Game :: render(double dt)
{

// DEBUG FPS%i,static_cast< int>(1 / dt));
static bool seizure = false;
seizure =!seizure;
//(seizure )?getScreen().setBackgroundColor(0.333f,0.003f,0.082f):getScreen()。setBackgroundColor(0.803f,0.753f,0.573f);
static float angle = 0;
angle + = dt;
// DEBUG(ANGLE%f%f,cos(angle)/2.0f,sin(angle)/2.0f);

//使用我们之前创建的程序对象来渲染
GLfloat attrib [] = {cos(angle)/2.0f,sin( angle)/2.0f,0.0f,0.0f };

glVertexAttrib4fv(glGetAttribLocation(program,offset),attrib);


//绘制一点
glDrawArrays(GL_TRIANGLES,0,3);
}

void Game :: shutdown()
{
glDeleteProgram(program);
glDeleteVertexArrays(1,& vertex_array_object);
}

IO.cpp

  #includeIO.h

GLuint IO :: loadShader(const char * fileName,ShaderType shaderType)
{
std :: ifstream f(fileName,std :: ifstream :: binary);
ASSERT(fileName);
f.seekg(0,std :: ios :: end);
int length =(int)f.tellg();
f.seekg(0,std :: ios :: beg);
char * buffer = new char [length + 1];
f.read(buffer,length);
buffer [length] = 0;
f.close();

const GLchar * in =(const GLchar *)buffer;

GLuint着色器;
switch(shaderType)
{
case VERTEX:
shader = glCreateShader(GL_VERTEX_SHADER);
break;

case FRAGMENT:
shader = glCreateShader(GL_FRAGMENT_SHADER);
break;
}

glShaderSource(shader,1,& in,NULL);
glCompileShader(shader);


//记录
GLint maxLength = 255;
GLint rLength = 0;
glGetShaderiv(shader,GL_INFO_LOG_LENGTH,& maxLength);

GLchar * err = new char [maxLength];
glGetShaderInfoLog(shader,maxLength,& rLength,err);

DEBUGSTR((char *)err);

delete [] err;
delete [] buffer;

GLint isCompiled = 0;
glGetShaderiv(shader,GL_COMPILE_STATUS,& isCompiled);
ASSERT(isCompiled == GL_TRUE);


返回着色器;
}

进入点/游戏循环


$ b b

  int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{
//创建虚拟窗口
HWND hWnd = getDummyWindow();
HDC hdc = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd = getWindowsPixelFormatStruct();
int chosenPixelFormat = ChoosePixelFormat(hdc,& pfd);
ASSERT(chosenPixelFormat!= 0);
int result = SetPixelFormat(hdc,chosenPixelFormat,& pfd);
ASSERT(result!= NULL);

//创建渲染上下文
HGLRC hglrc = wglCreateContext(hdc);

wglMakeCurrent(hdc,hglrc);

//获得支持OpenGL版本
DEBUG(System OpenGL版本:%s,(char *)glGetString(GL_VERSION));
DEBUG(Windows像素格式:%i,chosenPixelFormat);

GLint major_version = 1;
GLint minor_version = 1;
glGetIntegerv(GL_MAJOR_VERSION,& major_version);
glGetIntegerv(GL_MINOR_VERSION,& minor_version);


GLenum err = glewInit();
ASSERT(GLEW_OK == err);

//获取OpenGL像素格式
int nPixCount = 0;
//指定我们关心的重要属性
int pixAttribs [] = {
WGL_SUPPORT_OPENGL_ARB,1,//必须支持OGL渲染
WGL_DRAW_TO_WINDOW_ARB,1,// pf运行一个窗口
WGL_RED_BITS_ARB,8,//至少8位的红色
WGL_GREEN_BITS_ARB,8,//至少8位绿色
WGL_BLUE_BITS_ARB,8,//至少8位blue
WGL_DEPTH_BITS_ARB,16,//至少16位深度
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,//必须硬件加速
WGL_PIXEL_TYPE_ARB,WGL_TYPE_RGBA_ARB,// pf应为RGBA类型
WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
0}; // Zero termination
//让OpenGL找到与我们的attribs相匹配的最相关的格式
//只得到一个格式。
wglChoosePixelFormatARB(hdc,
& pixAttribs [0],
NULL,
1,
& chosenPixelFormat,
(UINT *)& nPixCount );
ASSERT(chosenPixelFormat!= -1);
DEBUG(OpenGL pixel format:%i,chosenPixelFormat);

//清除虚拟对象

wglDeleteContext(hglrc);
ReleaseDC(hWnd,hdc);
DestroyWindow(hWnd);

//创建窗口
hWnd = getWindow(hInstance,TEXT(OpenGL Window),iCmdShow);
hdc = GetDC(hWnd);
result = SetPixelFormat(hdc,chosenPixelFormat,& pfd);
ASSERT(result!= NULL);

//创建OpenGL渲染上下文


GLint attribs [] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB,major_version,
WGL_CONTEXT_MINOR_VERSION_ARB, minor_version,
WGL_CONTEXT_PROFILE_MASK_ARB,WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
};
DEBUG(Using OpenGL version%i。%i,major_version,minor_version);

hglrc = wglCreateContextAttribsARB(hdc,0,attribs);
wglMakeCurrent(hdc,hglrc);

//获取渲染维度
RECT rc_dimensions;
GetClientRect(hWnd,& rc_dimensions);
glViewport(0,0,rc_dimensions.left-1,rc_dimensions.bottom-1); // set viewport


//设置游戏
游戏游戏;
game.getScreen()。setWidth(rc_dimensions.left-1);
game.getScreen()。setHeight(rc_dimensions.bottom-1);
game.getScreen()。setFrameCap(59.0f);



game.init();
game._getGameTimer()。elapsed_time();

//开始游戏循环
MSG msg;
float accum_time = 0.0f;
while(true)
{
if(PeekMessage(& msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;

TranslateMessage(& msg);
DispatchMessage(& msg);
}
accum_time + = game._getGameTimer()。elapsed_time();
if(accum_time> game.getScreen()._ getSPF())
{
game.render(game.getScreen()._ getSPF());

// Post render
SwapBuffers(hdc);
game.getScreen()。clearBuffer();

accum_time - = game.getScreen()。getSPF();
}
}

//关闭前清理
game.shutdown();
wglDeleteContext(hglrc);
ReleaseDC(hWnd,hdc);
DestroyWindow(hWnd);
UnregisterClass(TEXT(OPENGL),hInstance);

return 0;
}

OpenGL支援

 渲染器:Intel(R)HD Graphics 3000 
供应商:Intel
内存:2108 MB
版本:3.1.0 - Build 9.17.10.3347
着色语言版本:1.40 - Intel Build 9.17.10.3347


最大纹理大小:8192 x 8192
最大顶点纹理图像单位:16
最大纹理图像单位:16
最大几何纹理单位:0
最大各向异性过滤值:16
最大视口大小:8192 x 8192
最大片段距离:6
最大样本: 4


分机:129

GL_3DFX_texture_compression_FXT1
GL_ARB_color_buffer_float
GL_ARB_compatibility
GL_ARB_copy_buffer
GL_ARB_depth_buffer_float
GL_ARB_depth_clamp
GL_ARB_depth_texture
GL_ARB_draw_buffers
GL_ARB_draw_buffers_blend
GL_ARB_draw_elements_base_vertex
GL_ARB_draw_instanced
GL_ARB_explicit_attrib_location
GL_ARB_fragment_coord_conventions
GL_ARB_fragment_program
GL_ARB_fragment_program_shadow
GL_ARB_fragment_shader
GL_ARB_framebuffer_object
GL_ARB_framebuffer_sRGB
GL_ARB_half_float_pixel
GL_ARB_half_float_vertex
GL_ARB_instanced_arrays
GL_ARB_map_buffer_range
GL_ARB_multisample
GL_ARB_multitexture
GL_ARB_occlusion_query
GL_ARB_occlusion_query2
GL_ARB_pixel_buffer_object
GL_ARB_point_parameters
GL_ARB_point_sprite
GL_ARB_provoking_vertex
GL_ARB_sampler_objects
GL_ARB_seamless_cube_map
GL_ARB_shader_bit_encoding
GL_ARB_shader_objects
GL_ARB_shading_language_100
GL_ARB_shadow
GL_ARB_sync
GL_ARB_texture_border_clamp
GL_ARB_texture_buffer_object_rgb32
GL_ARB_texture_compression
GL_ARB_texture_compression_rgtc
GL_ARB_texture_cube_map
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_texture_float
GL_ARB_texture_non_power_of_two
GL_ARB_texture_query_lod
GL_ARB_texture_rectangle
GL_ARB_texture_rg
GL_ARB_texture_rgb10_a2ui
GL_ARB_timer_query
GL_ARB_transpose_matrix
GL_ARB_uniform_buffer_object
GL_ARB_vertex_array_bgra
GL_ARB_vertex_array_object
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_vertex_shader
GL_ARB_vertex_type_2_10_10_10_rev
GL_ARB_window_pos
GL_ATI_separate_stencil
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_blend_color
GL_EXT_blend_equation_separate
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_EXT_draw_buffers2
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample
GL_EXT_framebuffer_object
GL_EXT_gpu_program_parameters
GL_EXT_multi_draw_arrays
GL_EXT_packed_depth_stencil
GL_EXT_packed_float
GL_EXT_packed_pixels
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_specular_color
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture3D
GL_EXT_texture_array
GL_EXT_texture_compression_s3tc
GL_EXT_texture_edge_clamp
GL_EXT_texture_env_add
GL_EXT_texture_env_combine
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_integer
GL_EXT_texture_lod_bias
GL_EXT_texture_rectangle
GL_EXT_texture_shared_exponent
GL_EXT_texture_snorm
GL_EXT_texture_sRGB
GL_EXT_texture_swizzle
GL_EXT_transform_feedback
GL_IBM_texture_mirrored_repeat
GL_INTEL_map_texture
GL_INTEL_performance_queries
GL_NV_blend_square
GL_NV_conditional_render
GL_NV_primitive_restart
GL_NV_texgen_reflection
GL_SGIS_generate_mipmap
GL_SGIS_texture_edge_clamp
GL_SGIS_texture_lod
GL_WIN_swap_hint
WGL_ARB_buffer_region
WGL_ARB_create_context
WGL_ARB_extensions_string
WGL_ARB_framebuffer_sRGB
WGL_ARB_make_current_read
WGL_ARB_multisample
WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_ARB_pixel_format_float
WGL_EXT_depth_float
WGL_EXT_extensions_string
WGL_EXT_pixel_format_packed_float
WGL_EXT_swap_control
WGL_EXT_swap_control_tear

核心功能
v3.0(100% - 23/23)
v3.1(100% - 8/8)
v3.2(70% - 7/10)
v3.3(70% - 7/10)
v4.0(21% - 3/14)
v4.1(0% - 0/7)
v4.2(0% - 0/12)
v4.3(0% - 0/18)
v4 .4(0% - 0/10)

OpenGL驱动程序版本检查(当前版本:3.1.0 - Build 9.17.10.3347,最新版本:9.17.10.3347):
显示版本过旧驱动程序检测到
根据数据库,您可能没有为您的视频卡使用最新版本的显示驱动程序。

无ICD注册表项
当前OpenGL驱动程序不公开软件/ Microsoft / Windows(NT)/ CurrentVersion / OpenGLDrivers注册表项。无法检测驱动程序版本,驱动程序版本名称和文件名。

扩展验证:
GL_EXT_color_subtable没有被发现,但切入点glColorSubTableEXT
GL_EXT_paletted_texture没有被发现,但切入点glColorTableEXT
GL_EXT_paletted_texture没有被发现,但切入点glGetColorTableEXT
GL_EXT_paletted_texture没有被发现,但切入点glGetColorTableParameterfvEXT
GL_EXT_paletted_texture没有被发现,但切入点glGetColorTableParameterivEXT


解决方案

有几个问题需要解决,虽然我不知道他们是否会解决你的问题。 p>

不能保证vec4偏移中的将被分配给顶点属性位置 0 。您应该使用 glBindAttribLocation(...) 将其位置(之前链接)绑定到 0 ,或者通过名称使用 =https://www.opengl.org/sdk/docs/man4/xhtml/glGetAttribLocation.xml> glGetAttribLocation(...) ,而不是盲目地使用幻数 0 。一个程序链接后属性的位置只能分配给那些真正顶点属性的积极使用时,程序执行(就像制服)。所以你不能假设属性从0开始并按顺序分配,你实际上需要告诉GL提供它的位置,或者在链接后查询它。



是真正有趣的地方... #version 140 core 。在OpenGL 3.2(GLSL 1.50)之前, 核心 确实没有任何意义。我很惊讶你的GLSL编译器不抱怨这个。事实上,由GLSL 1.40规范定义的 #version 指令被限制为一个数字,没有别的,在1.50添加了一个可选的配置文件名称。你应该检查着色器信息日志,即使对于成功编译的着色器,因为它们可能包含诸如此类的警告。



此外,在信息日志主题...链接器也产生一个。您在编译着色器时检查编译状态,但没有用于检查链接状态 的代码。



更新:



我注意到您用于查询着色器信息日志的代码有些错误


  1. 假设 DEBUGSTR(...)


  2. 如果编译器生成的内存不足,您将占用已分配的内存




    • 重写此: GLchar * err = new char [255 ]; 到此: GLchar * err = new char [maxLength];

    li>


The problem:

Outcome 1: I pass a vertex attribute to the shader, the program runs for 5 seconds, then the graphics driver stops responding and recovers but the program doesn't.

Outcome 2: I cap the framerate at 60 then do the same thing. The program runs fine, but when I try to pass different values for the vertex attribute in the same runtime it does not update the geometry (only the first vertex attribute passed works).

I'm using OpenGL version 3.1 with GLSL 140. (The highest my graphics card/driver will support)

What I have tried:

Internet browsing and reading tutorials. Since I do not understand OpenGL very well yet I think the problem is that I just do not know what to search for.

Note: Sorry if I have some bad OpenGL coding practices, I am still learning.

Code:

opengl2_vert.glsl

#version 140

in vec4 offset;

void main(void)
{
    // Declare a hard-coded array of positions
    vec4 vertices[3] = vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),
    vec4(-0.25, -0.25, 0.5, 1.0),
    vec4( 0.25, 0.25, 0.5, 1.0));
    // Index into our array using gl_VertexID
    gl_Position = vertices[gl_VertexID] - offset;
}

Game.cpp

#include "Game.h"


void Game::init()
{
    GLuint vertex_shader = getIO().loadShader("opengl2_vert.glsl", ShaderType::VERTEX);
    GLuint fragment_shader = getIO().loadShader("opengl2_frag.glsl", ShaderType::FRAGMENT);

    // Create program, attach shaders to it, and link it
    program = glCreateProgram();
    glAttachShader(program, vertex_shader);
    glAttachShader(program, fragment_shader);
    glLinkProgram(program);

    GLint isLinked = GL_FALSE;
    glGetProgramiv(program, GL_LINK_STATUS, &isLinked);

    // Logging
    GLint maxLength = 255;
    GLint rLength = 0;
    GLchar* err = new char[maxLength];

    // Vertex shader
    glGetShaderInfoLog(vertex_shader, maxLength, &rLength, err);
    DEBUGSTR((char*)err);

    // Fragment shader
    glGetShaderInfoLog(vertex_shader, maxLength, &rLength, err);
    DEBUGSTR((char*)err);

    // Program
    glGetProgramInfoLog(vertex_shader, maxLength, &rLength, err);
    DEBUGSTR((char*)err);

    delete [] err;
    ASSERT(isLinked == GL_TRUE);



    // Delete the shaders as the program has them now
    glDeleteShader(vertex_shader);
    glDeleteShader(fragment_shader);

    glUseProgram(program);

    // VAO
    glGenVertexArrays(1, &vertex_array_object); // Creates a VAO
    glBindVertexArray(vertex_array_object); // Attaches VAO to rendering context

}

void Game::render(double dt)
{

    //DEBUG("FPS %i", static_cast<int>(1/dt));
    static bool seizure = false;
    seizure = !seizure;
    //(seizure)?getScreen().setBackgroundColor(0.333f, 0.003f, 0.082f):getScreen().setBackgroundColor(0.803f, 0.753f, 0.573f);
    static float angle = 0;
    angle += dt;
    //DEBUG("ANGLE %f %f", cos(angle)/2.0f, sin(angle)/2.0f);

    // Use the program object we created earlier for rendering
    GLfloat attrib[] = {cos(angle)/2.0f, sin(angle)/2.0f, 0.0f, 0.0f};

    glVertexAttrib4fv(glGetAttribLocation(program, "offset"), attrib);


    // Draw one point
    glDrawArrays(GL_TRIANGLES, 0, 3);
}

void Game::shutdown()
{
    glDeleteProgram(program);
    glDeleteVertexArrays(1, &vertex_array_object);
}

IO.cpp

#include "IO.h"

GLuint IO::loadShader(const char* fileName, ShaderType shaderType)
{
    std::ifstream f(fileName, std::ifstream::binary);
    ASSERT(fileName);
    f.seekg(0, std::ios::end);   
    int length = (int)f.tellg();           
    f.seekg(0, std::ios::beg); 
    char* buffer = new char[length+1];  
    f.read(buffer, length); 
    buffer[length] = 0;
    f.close();                   

    const GLchar* in = (const GLchar *)buffer;

    GLuint shader;
    switch(shaderType)
    {
    case VERTEX:
        shader = glCreateShader(GL_VERTEX_SHADER);
        break;

    case FRAGMENT:
        shader = glCreateShader(GL_FRAGMENT_SHADER);
        break;
    }

    glShaderSource(shader, 1, &in, NULL);
    glCompileShader(shader);


    // Logging
    GLint maxLength = 255;
    GLint rLength = 0;
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);

    GLchar* err = new char[maxLength];
    glGetShaderInfoLog(shader, maxLength, &rLength, err);

    DEBUGSTR((char*)err);

    delete [] err;
    delete [] buffer;

    GLint isCompiled = 0;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
    ASSERT(isCompiled == GL_TRUE);


    return shader;
}

Entry point/Game loop

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
    // Creating dummy window
    HWND hWnd = getDummyWindow();
    HDC hdc = GetDC(hWnd);
    PIXELFORMATDESCRIPTOR pfd = getWindowsPixelFormatStruct();
    int chosenPixelFormat = ChoosePixelFormat( hdc, &pfd );
    ASSERT(chosenPixelFormat != 0);
    int result = SetPixelFormat(hdc, chosenPixelFormat, &pfd );
    ASSERT(result != NULL);

    // Creating rendering context
    HGLRC hglrc = wglCreateContext(hdc);

    wglMakeCurrent(hdc, hglrc);

    // Getting supported OpenGL version
    DEBUG("System OpenGL version: %s", (char*)glGetString(GL_VERSION));
    DEBUG("Windows pixel format: %i", chosenPixelFormat);

    GLint major_version = 1;
    GLint minor_version = 1;
    glGetIntegerv(GL_MAJOR_VERSION, &major_version);
    glGetIntegerv(GL_MINOR_VERSION, &minor_version);


    GLenum err = glewInit();
    ASSERT(GLEW_OK == err);

    // Getting OpenGL pixel format
    int nPixCount = 0;
    // Specify the important attributes we care about
    int pixAttribs[] = {
        WGL_SUPPORT_OPENGL_ARB, 1, // Must support OGL rendering
        WGL_DRAW_TO_WINDOW_ARB, 1, // pf that can run a window
        WGL_RED_BITS_ARB, 8, // At least 8 bits of red
        WGL_GREEN_BITS_ARB, 8, // At least 8 bits of green
        WGL_BLUE_BITS_ARB, 8, // At least 8 bits of blue
        WGL_DEPTH_BITS_ARB, 16, // At least 16 bits of depth
        WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, // Must be HW accelerated
        WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, // pf should be RGBA type
        WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
        0} ; // Zero termination
    // Ask OpenGL to find the most relevant format matching our attribs
    // Only get one format back.
    wglChoosePixelFormatARB(hdc,
        &pixAttribs[0],
        NULL,
        1,
        &chosenPixelFormat,
        (UINT*)&nPixCount);
    ASSERT(chosenPixelFormat != -1);
    DEBUG("OpenGL pixel format: %i", chosenPixelFormat);

    // Clean up dummies

    wglDeleteContext(hglrc);
    ReleaseDC(hWnd, hdc);
    DestroyWindow(hWnd);

    // Create window
    hWnd = getWindow(hInstance, TEXT("OpenGL Window"), iCmdShow);
    hdc = GetDC(hWnd);
    result = SetPixelFormat(hdc, chosenPixelFormat, &pfd );
    ASSERT(result != NULL);

    // Creating OpenGL rendering context


    GLint attribs[] =
    {
        WGL_CONTEXT_MAJOR_VERSION_ARB, major_version,
        WGL_CONTEXT_MINOR_VERSION_ARB, minor_version,
        WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
        0
    };
    DEBUG("Using OpenGL version %i.%i", major_version, minor_version);

    hglrc = wglCreateContextAttribsARB(hdc, 0, attribs);
    wglMakeCurrent(hdc, hglrc);

    // Getting rendering dimensions
    RECT rc_dimensions;
    GetClientRect(hWnd, &rc_dimensions);
    glViewport(0, 0, rc_dimensions.left-1, rc_dimensions.bottom-1); // set viewport


    // Setting up game
    Game game;
    game.getScreen().setWidth(rc_dimensions.left-1);
    game.getScreen().setHeight(rc_dimensions.bottom-1);
    game.getScreen().setFrameCap(59.0f);



    game.init();
    game._getGameTimer().elapsed_time();

    // Starting game loop
    MSG msg;
    float accum_time = 0.0f;
    while(true)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if(msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        accum_time += game._getGameTimer().elapsed_time();
        if(accum_time > game.getScreen()._getSPF())
        {
            game.render(game.getScreen()._getSPF());

            // Post render
            SwapBuffers(hdc);
            game.getScreen().clearBuffer();

            accum_time -= game.getScreen()._getSPF();
        }
    }

    // Cleaning up before shutdown
    game.shutdown();
    wglDeleteContext(hglrc);
    ReleaseDC(hWnd, hdc);
    DestroyWindow(hWnd);
    UnregisterClass(TEXT("OPENGL"), hInstance);

    return 0;
}

OpenGL support

Renderer: Intel(R) HD Graphics 3000
Vendor: Intel
Memory: 2108 MB
Version: 3.1.0 - Build 9.17.10.3347
Shading language version: 1.40 - Intel Build 9.17.10.3347


Max texture size: 8192 x 8192
Max vertex texture image units: 16
Max texture image units: 16
Max geometry texture units: 0
Max anisotropic filtering value: 16
Max viewport size: 8192 x 8192
Max Clip Distances: 6
Max samples: 4


Extensions: 129

GL_3DFX_texture_compression_FXT1
GL_ARB_color_buffer_float
GL_ARB_compatibility
GL_ARB_copy_buffer
GL_ARB_depth_buffer_float
GL_ARB_depth_clamp
GL_ARB_depth_texture
GL_ARB_draw_buffers
GL_ARB_draw_buffers_blend
GL_ARB_draw_elements_base_vertex
GL_ARB_draw_instanced
GL_ARB_explicit_attrib_location
GL_ARB_fragment_coord_conventions
GL_ARB_fragment_program
GL_ARB_fragment_program_shadow
GL_ARB_fragment_shader
GL_ARB_framebuffer_object
GL_ARB_framebuffer_sRGB
GL_ARB_half_float_pixel
GL_ARB_half_float_vertex
GL_ARB_instanced_arrays
GL_ARB_map_buffer_range
GL_ARB_multisample
GL_ARB_multitexture
GL_ARB_occlusion_query
GL_ARB_occlusion_query2
GL_ARB_pixel_buffer_object
GL_ARB_point_parameters
GL_ARB_point_sprite
GL_ARB_provoking_vertex
GL_ARB_sampler_objects
GL_ARB_seamless_cube_map
GL_ARB_shader_bit_encoding
GL_ARB_shader_objects
GL_ARB_shading_language_100
GL_ARB_shadow
GL_ARB_sync
GL_ARB_texture_border_clamp
GL_ARB_texture_buffer_object_rgb32
GL_ARB_texture_compression
GL_ARB_texture_compression_rgtc
GL_ARB_texture_cube_map
GL_ARB_texture_env_add
GL_ARB_texture_env_combine
GL_ARB_texture_env_crossbar
GL_ARB_texture_env_dot3
GL_ARB_texture_float
GL_ARB_texture_non_power_of_two
GL_ARB_texture_query_lod
GL_ARB_texture_rectangle
GL_ARB_texture_rg
GL_ARB_texture_rgb10_a2ui
GL_ARB_timer_query
GL_ARB_transpose_matrix
GL_ARB_uniform_buffer_object
GL_ARB_vertex_array_bgra
GL_ARB_vertex_array_object
GL_ARB_vertex_buffer_object
GL_ARB_vertex_program
GL_ARB_vertex_shader
GL_ARB_vertex_type_2_10_10_10_rev
GL_ARB_window_pos
GL_ATI_separate_stencil
GL_EXT_abgr
GL_EXT_bgra
GL_EXT_blend_color
GL_EXT_blend_equation_separate
GL_EXT_blend_func_separate
GL_EXT_blend_minmax
GL_EXT_blend_subtract
GL_EXT_clip_volume_hint
GL_EXT_compiled_vertex_array
GL_EXT_draw_buffers2
GL_EXT_draw_range_elements
GL_EXT_fog_coord
GL_EXT_framebuffer_blit
GL_EXT_framebuffer_multisample
GL_EXT_framebuffer_object
GL_EXT_gpu_program_parameters
GL_EXT_multi_draw_arrays
GL_EXT_packed_depth_stencil
GL_EXT_packed_float
GL_EXT_packed_pixels
GL_EXT_rescale_normal
GL_EXT_secondary_color
GL_EXT_separate_specular_color
GL_EXT_shadow_funcs
GL_EXT_stencil_two_side
GL_EXT_stencil_wrap
GL_EXT_texture3D
GL_EXT_texture_array
GL_EXT_texture_compression_s3tc
GL_EXT_texture_edge_clamp
GL_EXT_texture_env_add
GL_EXT_texture_env_combine
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_integer
GL_EXT_texture_lod_bias
GL_EXT_texture_rectangle
GL_EXT_texture_shared_exponent
GL_EXT_texture_snorm
GL_EXT_texture_sRGB
GL_EXT_texture_swizzle
GL_EXT_transform_feedback
GL_IBM_texture_mirrored_repeat
GL_INTEL_map_texture
GL_INTEL_performance_queries
GL_NV_blend_square
GL_NV_conditional_render
GL_NV_primitive_restart
GL_NV_texgen_reflection
GL_SGIS_generate_mipmap
GL_SGIS_texture_edge_clamp
GL_SGIS_texture_lod
GL_WIN_swap_hint
WGL_ARB_buffer_region
WGL_ARB_create_context
WGL_ARB_extensions_string
WGL_ARB_framebuffer_sRGB
WGL_ARB_make_current_read
WGL_ARB_multisample
WGL_ARB_pbuffer
WGL_ARB_pixel_format
WGL_ARB_pixel_format_float
WGL_EXT_depth_float
WGL_EXT_extensions_string
WGL_EXT_pixel_format_packed_float
WGL_EXT_swap_control
WGL_EXT_swap_control_tear

Core features
v3.0 (100 % - 23/23)
v3.1 (100 % - 8/8)
v3.2 (70 % - 7/10)
v3.3 (70 % - 7/10)
v4.0 (21 % - 3/14)
v4.1 (0 % - 0/7)
v4.2 (0 % - 0/12)
v4.3 (0 % - 0/18)
v4.4 (0 % - 0/10)

OpenGL driver version check (Current: 3.1.0 - Build 9.17.10.3347, Latest known: 9.17.10.3347):
Outdated version of display drivers detected
According the database, you are might be not using the latest version of display drivers for your video card.

No ICD registry entry
The current OpenGL driver doesn't expose the SOFTWARE/Microsoft/Windows (NT)/CurrentVersion/OpenGLDrivers registry entry. Unable to detect the driver version, driver revision name and filename.

Extension verification: 
GL_EXT_color_subtable was not found, but has the entry point glColorSubTableEXT 
GL_EXT_paletted_texture was not found, but has the entry point glColorTableEXT 
GL_EXT_paletted_texture was not found, but has the entry point glGetColorTableEXT 
GL_EXT_paletted_texture was not found, but has the entry point glGetColorTableParameterfvEXT 
GL_EXT_paletted_texture was not found, but has the entry point glGetColorTableParameterivEXT 

解决方案

There are a few issues that need to be addressed, although I do not know if they will solve your problem.

There is no guarantee that in vec4 offset is going to be assigned to vertex attribute location 0. You should use glBindAttribLocation (...) to bind its location (before linking) to 0, or query the location (after linking) by name using glGetAttribLocation (...) rather than blindly using the magic number 0. Attribute locations are assigned after a program is linked and only to vertex attributes that are actually actively used when the program executes (just like uniforms). So you cannot assume that the attributes start at 0 and are assigned sequentially, you actually need to tell GL what location to give it, or query it after linking.

But here is where things get really funny... #version 140 core. The word core really did not have any significance prior to OpenGL 3.2 (GLSL 1.50). I am surprised your GLSL compiler is not complaining about this. In fact, the #version directive defined by the GLSL 1.40 spec is limited to a number and nothing else, in 1.50 an optional profile name was added. You should check the shader info log even for shaders that successfully compile because they may contain warnings such as this.

Also, while on the topic of info logs... the linker produces one as well. You are checking the compile status when you compile your shaders, but you have no code that checks the link status.

Update:

I noticed a few things wrong with the code you are using to query your shader info log as well:

  1. Assuming DEBUGSTR (...) does not delete the pointer it is passed, you are going to leak memory when your shader fails to compile.

  2. You are going to overrun your allocated memory if the compiler produces a shader info log >= 255 characters in length.

    • Rewrite this: GLchar* err = new char[255]; to this: GLchar* err = new char[maxLength];.

这篇关于将属性传递给OpenGL顶点着色器奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆