相关疑难解决方法(0)

为什么CG着色器不能与GL 3.2一起使用?

我已经尝试了一切让OpenGL 3.2在我的游戏引擎中使用CG着色器进行渲染,但我没有运气.所以我决定做一个简单的小项目,但仍然着色器不起作用.从理论上讲,我的测试项目应该只渲染一个红色三角形,但它是白色的,因为着色器没有做任何事情.

我会在这里发布代码:

#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <GL/glew.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <SDL2/SDL.h>

int main()
{
    SDL_Window *mainwindow;
    SDL_GLContext maincontext;

    SDL_Init(SDL_INIT_VIDEO);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    mainwindow = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

    maincontext = SDL_GL_CreateContext(mainwindow);

    glewExperimental = GL_TRUE;
    glewInit();

    _CGcontext* cgcontext;
    cgcontext = cgCreateContext();
    cgGLRegisterStates(cgcontext);

    CGerror error;
    CGeffect effect;
    const char* string;
    std::string shader;

    shader =
            "struct VS_INPUT"
            "{"
            "   float3 pos              : ATTR0;"
            "};"

            "struct FS_INPUT" …
Run Code Online (Sandbox Code Playgroud)

opengl glew sdl nvidia cg-toolkit

1
推荐指数
1
解决办法
1155
查看次数

标签 统计

cg-toolkit ×1

glew ×1

nvidia ×1

opengl ×1

sdl ×1