void Init(void) { //Check if Opengl version is at least 3.0 const GLubyte* glVersion( glGetString(GL_VERSION) ); int major = glVersion[0] - '0'; int minor = glVersion[2] - '0'; if( major < 3 || minor < 0 ) { std::cerr<<"ERROR: Minimum OpenGL version required for this demo is 3.0. Your current version is "<<major<<"."<<minor<<std::endl; exit(-1); } //Init glew glewInit(); //Set clear color glClearColor(1.0, 1.0, 1.0, 0.0); //Create and bind the shader program gProgram = CompileShaders( gVertexShaderSource, gFragmentShaderSource ); glUseProgram(gProgram); glUniform1i(0,0); //Sampler refers to texture unit 0 GenerateGeometry(); GenerateArrayTexture(); }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(1024, 768); glutInitWindowPosition(100, 100); glutCreateWindow("Week 3"); InitializeGlutCallback(); GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: %s\n", glewGetErrorString(res)); return 1; } glClearColor(0.f, 0.f, 0.f, 0.f); CreateVertexBuffers(); CompileShaders(); glutMainLoop(); return 0; }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("Tutorial 13"); InitializeGlutCallbacks(); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); CreateIndexBuffer(); CompileShaders(); glutMainLoop(); return 0; }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(800, 600); glutInitWindowPosition(100, 100); glutCreateWindow("09 - Interpolation (OpenGL)"); InitializeGlutCallbacks(); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } printf("GL version: %s\n", glGetString(GL_VERSION)); glClearColor(0.f, 0.f, 0.f, 0.f); CreateVertexBuffer(); CompileShaders(); glutMainLoop(); return 0; }
ComputeShader::ComputeShader( Device& _Device, const char* _pShaderFileName, ID3DBlob* _pCS ) : Component( _Device ) , m_pCS( NULL ) , m_pShaderPath( NULL ) , m_pIncludeOverride( NULL ) , m_pMacros( NULL ) , m_bHasErrors( false ) #if defined(_DEBUG) || !defined(GODCOMPLEX) , m_LastShaderModificationTime( 0 ) #endif #ifdef COMPUTE_SHADER_COMPILE_THREADED , m_hCompileThread( 0 ) #endif { #if defined(_DEBUG) || !defined(GODCOMPLEX) m_pShaderFileName = CopyString( _pShaderFileName ); #endif #ifndef GODCOMPLEX m_pShaderPath = GetShaderPath( _pShaderFileName ); m_Pointer2FileName.Add( NULL, m_pShaderPath ); #endif ASSERT( _pCS != NULL, "You can't provide a NULL CS blob!" ); CompileShaders( NULL, _pCS ); }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("Homework 3: camera"); glutGameModeString("1280x1024@32"); glutEnterGameMode(); InitializeGlutCallbacks(); pGameCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT); GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); CreateIndexBuffer(); CompileShaders(); glutMainLoop(); return 0; }
int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(200, 200); glutInitWindowSize(1024, 768); glutCreateWindow("Tutorial 06"); InitializeGlutCallBacks(); GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error : '%s\n", glewGetErrorString(res)); return 1; } printf("GL version : %s\n", glGetString(GL_VERSION)); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); CompileShaders(); glutMainLoop(); return 0; }
void glut_initialization () { glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize(D_W * 4, D_H * 4); glutInitWindowPosition(D_X_INIT, D_Y_INIT); glutCreateWindow("Tutorial 06"); if (g_fullscreen) { //glutGameModeString("640x480:32@1000"); glutGameModeString ("1280x960:32@60"); //glutGameModeString("1920x1080:32@1000"); glutEnterGameMode (); } InitializeGlutCallbacks(); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); exit (1); } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CompileShaders(); glUniform1i(gSampler, 0); core.init (); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); }
bool TextureCache::Initialize() { m_texture_upload_buffer = StreamBuffer::Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, INITIAL_TEXTURE_UPLOAD_BUFFER_SIZE, MAXIMUM_TEXTURE_UPLOAD_BUFFER_SIZE); if (!m_texture_upload_buffer) { PanicAlert("Failed to create texture upload buffer"); return false; } if (!CreateRenderPasses()) { PanicAlert("Failed to create copy render pass"); return false; } m_texture_converter = std::make_unique<TextureConverter>(); if (!m_texture_converter->Initialize()) { PanicAlert("Failed to initialize texture converter."); return false; } if (!CompileShaders()) { PanicAlert("Failed to compile one or more shaders"); return false; } return true; }
void App::ScanInput( float dt ) { if(GetFocus() == mainWnd) { // update shaders if necessary if(GetAsyncKeyState(VK_F1) & 0x8000) CompileShaders(); // Camera movement if (GetAsyncKeyState('W') & 0x8000) viewports[0].Walk(10.f * dt); if (GetAsyncKeyState('S') & 0x8000) viewports[0].Walk(-10.f * dt); if (GetAsyncKeyState('A') & 0x8000) viewports[0].Strafe(-10.f * dt); if (GetAsyncKeyState('D') & 0x8000) viewports[0].Strafe(10.f * dt); if(GetAsyncKeyState('Y') & 0x8000) shaderParams->lacunarity += 0.01f; if(GetAsyncKeyState('H') & 0x8000) shaderParams->lacunarity -= 0.01f; if(GetAsyncKeyState('U') & 0x8000) shaderParams->gain += 0.005f; if(GetAsyncKeyState('J') & 0x8000) shaderParams->gain -= 0.005f; if(GetAsyncKeyState('I') & 0x8000) shaderParams->gradOffset += 0.01f; if(GetAsyncKeyState('K') & 0x8000) shaderParams->gradOffset -=0.01f; if(GetAsyncKeyState('O') & 0x8000) shaderParams->gradScale += 0.01f; if(GetAsyncKeyState('L') & 0x8000) shaderParams->gradScale -=0.01f; } }
// Initialize application window // Most of the error checking omitted bool App::Init() { /* viewports[0].SetVPSize(winWidth/2, winHeight/2); Viewport vp(viewports[0]); vp.SetVPPosition(winWidth/2, winHeight/2); viewports.push_back(vp); */ if(!InitWindow()) return false; if(!InitD3D()) return false; // Call resize to do rest of window initialization Resize(); if(!CompileShaders()) return false; // Set up sampler states for perlin noise SetupSamplers(); // Set up lookup textures for perlin noise SetupTextures(); // Initialize vertex buffer with canvas quad InitCanvas(); // Init default viewport viewports[0].RefreshBuffer(); // Initialize viewport buffer D3D11_SUBRESOURCE_DATA vpbufData; vpbufData.pSysMem = viewports[0].GetBufferData(); vpbufData.SysMemPitch = NULL; vpbufData.SysMemSlicePitch = NULL; HR(dev->CreateBuffer(&Viewport::viewportBufferDesc, NULL, &viewportBuffer)); // Initialize shader params buffer; D3D11_BUFFER_DESC shaderBufferDesc= { sizeof(ShaderParams), D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, D3D11_CPU_ACCESS_WRITE, 0 }; D3D11_SUBRESOURCE_DATA shaderBuffer; shaderBuffer.pSysMem = shaderParams; shaderBuffer.SysMemPitch = NULL; shaderBuffer.SysMemSlicePitch = NULL; HR(dev->CreateBuffer(&shaderBufferDesc, &shaderBuffer, &shaderParamsBuffer)); // And finally update the window UpdateWindow(mainWnd); return true; }
bool Shader::Reload(ID3D11Device* device) { Shader copy(this->mDescriptor); copy.mID = this->mID; ReleaseResources(); this->mID = copy.mID; return CompileShaders(device, copy.mDescriptor); }
TextureCache::TextureCache() { CompileShaders(); s_ActiveTexture = -1; for (auto& gtex : s_Textures) gtex = -1; }
Shader::Shader(const char* vertexFile, const char* fragmentFile) { string vertexCode = FileUtils::GetFileContents(vertexFile); string fragmentCode = FileUtils::GetFileContents(fragmentFile); const char* vertexSource = vertexCode.c_str(); const char* fragmentSource = fragmentCode.c_str(); CompileShaders(vertexSource, fragmentSource); }
bool PickingShader::Compile() { if (CompileShaders(PickingVertexShader, NULL, PickingFragmentShader) == false) { PrintShaderWarning("Compiling shaders failed."); return false; } vertex_position_ = glGetAttribLocation(program_, "vertex_position"); vertex_index_ = glGetAttribLocation(program_, "vertex_index"); MVP_ = glGetUniformLocation(program_, "MVP"); return true; }
int main(int argc, char** argv) { // Magick::InitializeMagick(*argv); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("Tutorial 16"); glutGameModeString("1280x1024@32"); // glutEnterGameMode(); InitializeGlutCallbacks(); pGameCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glFrontFace(GL_CW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); CreateVertexBuffer(); CreateIndexBuffer(); CompileShaders(); glUniform1i(gSampler, 0); pTexture = new Texture(GL_TEXTURE_2D, "../Content/test.png"); if (!pTexture->Load()) { return 1; } gPersProjInfo.FOV = 60.0f; gPersProjInfo.Height = WINDOW_HEIGHT; gPersProjInfo.Width = WINDOW_WIDTH; gPersProjInfo.zNear = 1.0f; gPersProjInfo.zFar = 100.0f; glutMainLoop(); return 0; }
void Renderer::Init( LPDIRECT3DDEVICE9 pD3DDevice, int iXPos, int iYPos, int iWidth, int iHeight, float fPixelRatio ) { DebugConsole::Log("Renderer: Viewport x%d, y%d, w%d, h%d, pixel%f\n", iXPos, iYPos, iWidth, iHeight, fPixelRatio ); m_pD3DDevice = pD3DDevice; g_viewport.X = iXPos; g_viewport.Y = iYPos; g_viewport.Width = iWidth; g_viewport.Height = iHeight; g_viewport.MinZ = 0; g_viewport.MaxZ = 1; g_defaultAspect = ((float)iWidth / iHeight) * fPixelRatio; m_pD3DDevice->CreateDepthStencilSurface(1024, 1024, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, TRUE, &g_depthBuffer, NULL); /* if (D3D_OK != m_pD3DDevice->GetDepthStencilSurface(&g_oldDepthBuffer)) { DebugConsole::Log("Renderer: No default depth buffer\n", iXPos, iYPos, iWidth, iHeight, fPixelRatio ); //OutputDebugString("Vortex INFO: Renderer::Init - Failed to Get old depth stencil\n"); // Create our own // D3DSURFACE_DESC desc; // g_backBuffer->GetDesc(&desc); // g_device->CreateDepthStencilSurface(desc.Width, desc.Height, D3DFMT_LIN_D24S8, 0, &g_oldDepthBuffer); // g_ownDepth = true; } else { // g_ownDepth = false; } */ { char fullname[512]; sprintf_s(fullname, 512, "%sfont.bmp", g_TexturePath ); m_pTextureFont = LoadTexture( fullname, false ); } D3DXCreateMatrixStack(0, &g_matrixStack); g_matrixStackLevel = 0; g_scratchTexture = CreateTexture( 512, 512 ); CompileShaders(); CreateCubeBuffers(); CreateFonts(); }
void ComputeShader::RebuildShader() { DWORD ErrorCode = WaitForSingleObject( m_hCompileMutex, 30000 ); #ifdef _DEBUG ASSERT( ErrorCode == WAIT_OBJECT_0, "Failed shader rebuild after 30 seconds waiting for access !" ); #else if ( ErrorCode != WAIT_OBJECT_0 ) ExitProcess( -1 ); // Failed ! #endif #endif // Reload file FILE* pFile = NULL; fopen_s( &pFile, m_pShaderFileName, "rb" ); // ASSERT( pFile != NULL, "Failed to open shader file !" ); if ( pFile == NULL ) { // Failed! Unlock but don't update time stamp so we try again next time... Unlock(); return; } fseek( pFile, 0, SEEK_END ); size_t FileSize = ftell( pFile ); fseek( pFile, 0, SEEK_SET ); char* pShaderCode = new char[FileSize+1]; fread_s( pShaderCode, FileSize, 1, FileSize, pFile ); pShaderCode[FileSize] = '\0'; fclose( pFile ); // Compile CompileShaders( pShaderCode ); delete[] pShaderCode; // Release the mutex: it's now safe to access the shader ! Unlock(); #ifdef COMPUTE_SHADER_COMPILE_THREADED // Close the thread once we're done ! if ( m_hCompileThread ) CloseHandle( m_hCompileThread ); m_hCompileThread = 0; #endif }
TextureShader::TextureShader(ID3D11Device *device, ID3D11DeviceContext *context) { if (!CompileShaders()) { DebugOut("TextureShader::CompileShaders failed!\n"); return; } if (!CreateShaders(device)) { DebugOut("TextureShader::CreateShaders failed!\n"); return; } if (!MakeBuffers(device, context)) { DebugOut("TextureShader::MakeBuffers failed!\n"); return; } };
void init() { // Create 3 vertices that make up a triangle that fits on the viewport GLfloat vertices[] = {-1.0f, -1.0f, 0.0f, 1.0, 1.0f, -1.0f, 0.0f, 1.0, 0.0f, 1.0f, 0.0f, 1.0}; // Create a color array that identfies the colors of each vertex (format R, G, B, A) GLfloat colors[] = {0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f}; // Set up the shaders player_init(); GLuint shaderProgramID = CompileShaders(); // load teapot mesh into a vertex buffer array generateObjectBufferTeapot (); computeMatricesFromInputs(); glutSetCursor(GLUT_CURSOR_NONE); // glutWarpPointer(1024/2, 768/2); }
BloomEffect::BloomEffect(const uint32 Tex1, const uint32 Width, const uint32 Height) : IEffect(Width, Height) { // Set RTT UseRTT(Tex1); // Create Fragment Shader FragmentShaderString = "const float BloomSize = 1.0/2048.0;" "uniform sampler2D uTex0;" "varying vec2 vTexcoord;" "void main()" "{" "vec4 sum = vec4(0);" "vec2 texcoord = vTexcoord;" "int j;" "int i;" "for( i= -4 ;i < 4; i++)" "{" "for (j = -3; j < 3; j++)" "{" "sum += texture2D(uTex0, texcoord + vec2(j, i)*0.004) * 0.25;" "}" "}" "if (texture2D(uTex0, texcoord).r < 0.3)" "{" "gl_FragColor = sum*sum*0.012 + texture2D(uTex0, texcoord);" "}" "else" "{" "if (texture2D(uTex0, texcoord).r < 0.5)" "{" "gl_FragColor = sum*sum*0.009 + texture2D(uTex0, texcoord);" "}" "else" "{" "gl_FragColor = sum*sum*0.0075 + texture2D(uTex0, texcoord);" "}" "}" "}"; CompileShaders(); }
void MyView::ResetConsole() { system("cls"); //Application instructions std::cout << "ABOUT" << std::endl; std::cout << "Spice My Sponza - 3D Graphics Programming ICA1" << std::endl; std::cout << "P4011584 - Frederic Babord 2015 - 2016" << std::endl << std::endl; std::cout << "Submission date: 04th February 2016" << std::endl << std::endl; std::cout << "INSTRUCTIONS" << std::endl; std::cout << "Press F1 to enable camera animation." << std::endl; std::cout << "Press F2 to view the direction of the vertex normals." << std::endl; std::cout << "Press F3 to enable wireframe mode." << std::endl; std::cout << "Press F4 to change rendering mode (Fill, Line, Point)." << std::endl; std::cout << "Press F5 to recompile the shader." << std::endl << std::endl; std::cout << "Press Q to reduce the normal line length." << std::endl; std::cout << "Press E to increase the normal line length." << std::endl; std::cout << "Press Z to reduce the specular intensity smudge factor." << std::endl; std::cout << "Press C to increase the specular intensity smudge factor." << std::endl << std::endl; std::cout << "Press Esc to Close." << std::endl << std::endl; CompileShaders(); }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutInitWindowPosition(200, 200); glutCreateWindow("Tutorial 15 - Camera Control Part2"); // glutGameModeString("1920*1200@32"); // glutEnterGameMode(); InitializeGlutCallbacks(); pGameCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res)); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); CreateIndexBuffer(); CompileShaders(); gPersProjInfo.FOV = 60.0f; gPersProjInfo.Height = WINDOW_HEIGHT; gPersProjInfo.Width = WINDOW_WIDTH; gPersProjInfo.zNear = 1.0f; gPersProjInfo.zFar = 100.0f; glutMainLoop(); return 1; }
// Only used by Headless! TODO: Remove void DirectxInit(HWND window) { pD3D = Direct3DCreate9( D3D_SDK_VERSION ); // Set up the structure used to create the D3DDevice. Most parameters are // zeroed out. We set Windowed to TRUE, since we want to do D3D in a // window, and then set the SwapEffect to "discard", which is the most // efficient method of presenting the back buffer to the display. And // we request a back buffer format that matches the current desktop display // format. D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); // TODO? d3dpp.Windowed = TRUE; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.BackBufferCount = 1; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //d3dpp.PresentationInterval = (useVsync == true)?D3DPRESENT_INTERVAL_ONE:D3DPRESENT_INTERVAL_IMMEDIATE; //d3dpp.RingBufferParameters = d3dr; HRESULT hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pD3Ddevice); if (hr != D3D_OK) { // TODO } #ifdef _XBOX pD3Ddevice->SetRingBufferParameters( &d3dr ); #endif std::string errorMessage; CompileShaders(errorMessage); fbo_init(pD3D); }
int main(int args, char **argv) { glutInit(&args, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(0,0); glutInitWindowSize(1024, 600); glutCreateWindow("tutorial 8"); InitializeGlutCallBacks(); GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "glew init error \n"); return 1; } glClearColor(0.0f, 0.0f, 0.0f, 0.0f); CreateVertexBuffer(); CompileShaders(); glutMainLoop(); system("pause"); return 0; }
void FShaderManager::Recompile() { Clean(); CompileShaders(); }
// Construct visual object display list. void Sphere::initialize() { CompileShaders(); // vector containers to hold data // vertice positions vector<vec3> v; vector<vec3> n; GLuint VBO, NBO, IBO; // Vector contains indexes to the data vector<unsigned int> indices; // Declare the variables we are going to use float X1,Y1,X2,Y2,Z1,Z2; float inc1,inc2,inc3,inc4, Radius1, Radius2; for(int w = 0; w < Resolution; w++) { for(int h = (-Resolution/2); h < (Resolution/2); h++){ inc1 = (w/(float)Resolution) * 2 * PI; inc2 = ((w+1)/(float)Resolution) * 2 * PI; inc3 = (h/(float)Resolution) * PI; inc4 = ((h+1)/(float)Resolution) * PI; X1 = sin(inc1); Y1 = cos(inc1); X2 = sin(inc2); Y2 = cos(inc2); // store the upper and lower radius, remember everything is going to be drawn as triangles Radius1 = Radius*cos(inc3); Radius2 = Radius*cos(inc4); Z1 = Radius*sin(inc3); Z2 = Radius*sin(inc4); // insert the triangle coordinates v.push_back( vec3( Radius1*X1, Z1, Radius1*Y1)); v.push_back( vec3( Radius1*X2, Z1, Radius1*Y2)); v.push_back( vec3( Radius2*X2, Z2, Radius2*Y2)); v.push_back( vec3( Radius1*X1, Z1, Radius1*Y1)); v.push_back( vec3( Radius2*X2, Z2, Radius2*Y2)); v.push_back( vec3( Radius2*X1, Z2, Radius2*Y1)); n.push_back( vec3(X1,Z1,Y1) / length( vec3(X1,Z1,Y1) )); n.push_back( vec3(X2,Z1,Y2) / length( vec3(X2,Z1,Y2) )); n.push_back( vec3(X2,Z2,Y2) / length( vec3(X2,Z2,Y2) )); n.push_back( vec3(X1,Z1,Y1) / length( vec3(X1,Z1,Y1) )); n.push_back( vec3(X2,Z2,Y2) / length( vec3(X2,Z2,Y2) )); n.push_back( vec3(X1,Z2,Y1) / length( vec3(X1,Z2,Y1) )); } } for ( unsigned int i=0; i < v.size(); i++ ) { indices.push_back( i ); } glGenVertexArrays (1, &vertexArrayObject); glBindVertexArray( vertexArrayObject ); // finally, create the buffers and bind the data to them glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); // Buffer for vertex data glBufferData(GL_ARRAY_BUFFER, v.size() * sizeof(vec3), &v[0], GL_STATIC_DRAW); //Buffering vertex data glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); glGenBuffers(1, &NBO); glBindBuffer(GL_ARRAY_BUFFER, NBO); glBufferData(GL_ARRAY_BUFFER, n.size() * sizeof(vec3), &n[0], GL_STATIC_DRAW); glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(1); // Generate a buffer for the indices as well glGenBuffers(1, &IBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0] , GL_STATIC_DRAW); // store the number of indices for later use numberOfIndices = indices.size(); v.clear(); n.clear(); indices.clear(); VisualObject::initialize(); } // end initialize
int C_DECL main(int argc, char* argv[]) { ProcessArguments(argc, argv); if (Options & EOptionDumpConfig) { printf("%s", DefaultConfig); if (Worklist.empty()) return ESuccess; } if (Options & EOptionDumpVersions) { printf("Glslang Version: %s %s\n", GLSLANG_REVISION, GLSLANG_DATE); printf("ESSL Version: %s\n", glslang::GetEsslVersionString()); printf("GLSL Version: %s\n", glslang::GetGlslVersionString()); std::string spirvVersion; glslang::GetSpirvVersion(spirvVersion); printf("SPIR-V Version %s\n", spirvVersion.c_str()); printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision); if (Worklist.empty()) return ESuccess; } if (Worklist.empty()) { usage(); } ProcessConfigFile(); // // Two modes: // 1) linking all arguments together, single-threaded, new C++ interface // 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface // if (Options & EOptionLinkProgram || Options & EOptionOutputPreprocessed) { glslang::InitializeProcess(); CompileAndLinkShaders(); glslang::FinalizeProcess(); } else { ShInitialize(); bool printShaderNames = Worklist.size() > 1; if (Options & EOptionMultiThreaded) { const int NumThreads = 16; void* threads[NumThreads]; for (int t = 0; t < NumThreads; ++t) { threads[t] = glslang::OS_CreateThread(&CompileShaders); if (! threads[t]) { printf("Failed to create thread\n"); return EFailThreadCreate; } } glslang::OS_WaitForAllThreads(threads, NumThreads); } else CompileShaders(0); // Print out all the resulting infologs for (int w = 0; w < NumWorkItems; ++w) { if (Work[w]) { if (printShaderNames) PutsIfNonEmpty(Work[w]->name.c_str()); PutsIfNonEmpty(Work[w]->results.c_str()); delete Work[w]; } } ShFinalize(); } if (CompileFailed) return EFailCompile; if (LinkFailed) return EFailLink; return 0; }
int main(int argc,char * argv[]) { // Initialize GLUT glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(500, 400); // Center window glutInitWindowPosition( glutGet(GLUT_SCREEN_WIDTH)/2-glutGet(GLUT_INIT_WINDOW_WIDTH)/2, glutGet(GLUT_SCREEN_HEIGHT)/2-glutGet(GLUT_INIT_WINDOW_HEIGHT)/2); glutCreateWindow("Texture Example"); glutCreateMenu(NULL); // Set GLUT callbacks glutDisplayFunc(DisplayCB); //glutCloseFunc(closeEvent); //glutReshapeFunc(resizeEvent); //glutMotionFunc(mouseEvent); //glutMouseFunc(mouseButtonEvent); //glutPassiveMotionFunc(mousePassiveEvent); //glutKeyboardFunc(keyboardEvent); //glutSpecialFunc(keySpecEvent); // Must be done after glut is initialized! GLenum res = glewInit(); if (res != GLEW_OK) { fprintf( stderr, "Error: ''.\n", glewGetErrorString(res)); return 1; } printf("GL version: %s.\n", glGetString(GL_VERSION) ); glClearColor(0.0f, .3f, 0.0f, 1.0f); // create vertex array object GLuint iVAO; glGenVertexArrays(1, &iVAO); glBindVertexArray(iVAO); // create a vertex buffer object and copy the vertex data to it GLfloat vertices[] = { // pos, color, texcoord -0.5, -0.5, 0, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, // top-left 0.5, -0.5, 0, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // top-left 0.5, 0.5, 0, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, // top-left -0.5, 0.5, 0, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, // top-left }; glGenBuffers(1, &g_iVBO); glBindBuffer(GL_ARRAY_BUFFER, g_iVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); unsigned int indices[] = { 0, 1, 2, 0, 2, 3 }; glGenBuffers(1, &g_iEBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_iEBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); CompileShaders(); // Load textures GLuint texId; glGenTextures(1, &texId); glActiveTexture(GL_TEXTURE0); // for one tex this can be ignore, it is designed for multiply texture. glBindTexture(GL_TEXTURE_2D, texId); // Black/white checkerboard float pixels[] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f }; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);GL_LINEAR; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);GL_LINEAR; // Call the GLUT main loop glutMainLoop(); glDeleteTextures(1, &texId); glDeleteProgram(g_iShaderProgram); glDeleteBuffers(1, &g_iVBO); glDeleteVertexArrays(1, &iVAO); return 0; }
FShaderManager::FShaderManager() { CompileShaders(); }