void init() { // Load shaders and use the resulting shader program GLuint drawProg = InitShader("Draw.vertex", "Draw.fragment"); GLuint shadowProg = InitShader("ShadowMap.vertex", "ShadowMap.fragment"); glUseProgram(drawProg); meshSetup(Global::red_opaque, 1.2); const mat4 projection = Perspective(Global::FOV, 1.0f, 0.0078125f, 16.0f) * translate(0.0f, 0.0f, 0.75f) * scale(10.0f); Global::root = new RenderGraph( drawProg, shadowProg, *genIdyll(5, 1.2f), projection ); Global::sun = new RenderGraph( drawProg, shadowProg, *genSun( translate(16.0 * Global::sunVec) * scale(0.4f) * rX(M_PI/2.0) ), projection ); help(); }
void init() { /*select clearing (background) color*/ glClearColor(1.0, 1.0, 1.0, 1.0); //populate our arrays spherevertcount = generateSphere(2, 10); // Load shaders and use the resulting shader program program1 = InitShader( "vshader-lighting.glsl", "fshader-lighting.glsl" ); program2 = InitShader( "vshader-phongshading.glsl", "fshader-phongshading.glsl" ); program3 = InitShader( "vshader-celshading.glsl", "fshader-celshading.glsl" ); // Create a vertex array object glGenVertexArrays( 1, &vao[0] ); // Create and initialize any buffer objects glBindVertexArray( vao[0] ); glGenBuffers( 2, &vbo[0] ); glBindBuffer( GL_ARRAY_BUFFER, vbo[0] ); glBufferData( GL_ARRAY_BUFFER, spherevertcount*sizeof(vec4), sphere_verts, GL_STATIC_DRAW); //and now our colors for each vertex glBindBuffer( GL_ARRAY_BUFFER, vbo[1] ); glBufferData( GL_ARRAY_BUFFER, spherevertcount*sizeof(vec3), sphere_normals, GL_STATIC_DRAW ); setupShader(program1); //Only draw the things in the front layer glEnable(GL_DEPTH_TEST); }
void VerticalBlurShader::changeShaderBlur(bool isHighBlur) { if (isHighBlur) { InitShader(L"../shaders/increasedVertBlur_vs.hlsl", L"../shaders/increasedVertBlur_ps.hlsl"); } else { InitShader(L"../shaders/verticalBlur_vs.hlsl", L"../shaders/verticalBlur_ps.hlsl"); } }
int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow("particle system"); glutDisplayFunc(myDisplay); glewExperimental = GL_TRUE; glewInit(); program = InitShader("vshader91.glsl", "fshader91.glsl"); myinit (); glutCreateMenu(main_menu); glutAddMenuEntry("more particles", 1); glutAddMenuEntry("fewer particles", 2); glutAddMenuEntry("faster", 3); glutAddMenuEntry("slower", 4); glutAddMenuEntry("larger particles", 5); glutAddMenuEntry("smaller particles", 6); glutAddMenuEntry("toggle gravity",7); glutAddMenuEntry("toggle restitution",8); glutAddMenuEntry("toggle repulsion",9); glutAddMenuEntry("quit",10); glutAttachMenu(GLUT_MIDDLE_BUTTON); glutIdleFunc(myIdle); glutReshapeFunc (myReshape); glutMainLoop(); }
// OpenGL initialization void init() { mesh(); // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vmesh.glsl", "fmesh.glsl" ); glUseProgram( program ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); timeParam = glGetUniformLocation(program, "time"); MVP_loc = glGetUniformLocation(program, "ModelViewProjection"); glClearColor( 1.0, 1.0, 1.0, 1.0 ); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); }
//SoundPlayerGuard spg; void initApp(){ //Seed the random number generator std::srand(std::time(NULL)); sProgram=InitShader("Resources/PhongShader_vertex.glsl","Resources/PhongShader_fragment.glsl"); initShaderVariables(sProgram); glClearColor( .05f, .075f, .1f, 1.f ); glClearColor( .3f, .2f, .25f, 1.f ); //lightBlue Sky glClearColor( .7f, .9f, .9f, 1.f ); //lightBlue Sky glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); //INIT THE LIGHTS for(int i=0;i<LIGHT_COUNT;i++){ wLights[i]=NULL; } //Null Scenes for(int i=0;i<SCENE_COUNT;i++){ wScenes[i]=NULL; } //viewFullscreen(); glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH)/2,glutGet(GLUT_WINDOW_HEIGHT)/2); glutSetCursor(GLUT_CURSOR_NONE); //setup scenes wScenes[0]=new Scene_1(); wScenes[currentLevel]->setup(); Globals::setHasFog(true); }
// OpenGL initialization void init() { srand(time(NULL)); numSquares = 0; drawSquares(0, 0, 1, 1, 4, 4); exitMaker(); // Create and initialize a buffer object // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader00_v110.glsl", "fshader00_v110.glsl" ); glUseProgram( program ); vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); color_loc = glGetUniformLocation(program, "color"); model_view_loc = glGetUniformLocation(program, "modelview"); glEnable( GL_DEPTH_TEST ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); }
void init() { // Create a vertex array object GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); /* set up vertex buffer object */ glGenBuffers(1, buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(quad_color), NULL, GL_STATIC_DRAW); program = InitShader("vshader52.glsl", "fshader52.glsl"); glUseProgram(program); loc = glGetAttribLocation(program, "vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); loc2 = glGetAttribLocation(program, "vColor"); glEnableVertexAttribArray(loc2); glVertexAttribPointer(loc2, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points))); glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */ }
void DexSkinMesh::Init() { m_iRenderFlag = 0; m_fAnimateRatio = 1.0f; m_eAniType = SkinMeshAnimateType_Loop; m_eMeshType = SkinMeshModelType_UnKnown; m_iAnimateStartTime = 0; m_iAnimateNowTime = 0; m_iAnimateEndTime = 0; m_iAnimateMaxTime = 0; m_pRootJoint = NULL; m_bHaveAnimation = true; m_bAnimate = true; m_iLightFlag = 0; m_pRootJoint = new Joint; m_pRootJoint->m_pFather = NULL; m_pRootJoint->str_name = "root_joint"; m_pRootJoint->id = _SKIN_MESH_ROOT_JOINT_ID; m_pRootJoint->frame_matrix.Identity(); m_pRootJoint->meshMatrix.Identity(); m_pRootJoint->localMeshMatrixInvert.Identity(); m_pRootJoint->world_matrix.Identity(); m_vecJoints.push_back(m_pRootJoint); SetRenderFlag(SKINMESH_RENDER_MESH); jointsMatrix = new D3DXMATRIX[sGetMaxJointCount()]; m_fJointScale = 1.0f; InitShader(); iHideMeshIndex = -1; }
int CreateShader(Shader* s, char* fname, GLenum type) { FILE* file = fopen(fname, "r"); int size; int bytes; int error; char buffer[1024]; memset(buffer, 0, 1024); if(!file){ error = errno; OutputDebugString(strerror(errno)); return -1; } fseek(file, 0, SEEK_END); size = ftell(file); rewind(file); bytes = fread(buffer, 1, size, file); InitShader(s, buffer, type); return bytes; }
void init () { glClearColor (0.0, 0.0, 0.0, 0.0); //Starte the Brownian motion head = getRandomStart(minX, maxX, minY, maxY); curr = head; glGenBuffers( 2, &buffers[0] ); glBindBuffer( GL_ARRAY_BUFFER, buffers[0] ); glBufferData( GL_ARRAY_BUFFER, sizeof(bBox), bBox, GL_STATIC_DRAW ); // Load shaders and use the resulting shader program program = InitShader( "vshader23_v110.glsl","fshader23_v110.glsl" ); glUseProgram( program ); projmat_loc = glGetUniformLocation(program, "projmat"); modelview_loc = glGetUniformLocation(program, "modelview"); draw_color_loc = glGetUniformLocation(program, "vColor"); // set up vertex attributes arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); width = maxX - minX; height = maxY - minY; }
PulsingPlanetShader::PulsingPlanetShader(ID3D11Device* device, HWND hwnd) : BaseShader(device, hwnd) { // Load our shader files. InitShader(L"../shaders/pulsing_planet_vs.hlsl", L"../shaders/pulsing_planet_ps.hlsl"); }
void myInit( void ) { // Load shaders and use the resulting shader program GLuint program = InitShader( "./tri.vert", "./tri.frag" ); glUseProgram( program ); // Create a vertex array object GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); // Create and initalize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); }
void init() { // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); /* set up buffer object */ glGenBuffers(1, buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(square), square, GL_STATIC_DRAW); program = InitShader("vshader48.glsl", "fshader48.glsl"); glUseProgram( program ); loc = glGetAttribLocation(program, "vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, 0, 0); matrix_loc = glGetUniformLocation(program, "model_view"); projection_loc = glGetUniformLocation(program, "projection"); color_loc = glGetUniformLocation(program, "fcolor"); for(int i =0; i<4; i++) for(int j =0; j<4;j++) m[i][j] = 0.0; m[0][0] = m[1][1] = m[2][2] = 1.0; m[3][1] = -1.0/light[1]; glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */ }
void Game::init(int* argcp, char** argvp) { glutInit(argcp, argvp); glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize (480, 480); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow ("Ablockalypse"); glutSetWindowTitle("Ablockalypse"); glutSetIconTitle("Ablockalypse"); glewExperimental = GL_TRUE; glewInit (); // do shader stuff here... GLuint program = InitShader( "vshader.glsl", "fshader.glsl" ); glUseProgram( program ); vPosition = glGetAttribLocation( program, "vPosition" ); vColor = glGetAttribLocation( program, "vColor" ); xlate = glGetUniformLocation( program, "xlate" ); initGeometry (paddle); initGeometry (ball); initBricks (); glEnable( GL_DEPTH_TEST ); glClearColor(0, 0, 0, 0); }
////////////////////////////////////////////////////////// //======================================================// // Constructor // //======================================================// // This will be used for initialising our shader files. // ////////////////////////////////////////////////////////// MasterShader::MasterShader(ID3D11Device* device, HWND hwnd) : BaseShader(device, hwnd) { // Load in our shader files. InitShader(L"../shaders/master_vs.hlsl", L"../shaders/quad_tessellation_hs.hlsl", L"../shaders/quad_tessellation_ds.hlsl", L"../shaders/master_ps.hlsl"); }
LightAlphaMapShader::LightAlphaMapShader(ID3D11Device* device, HWND hwnd, sz::ConstBufManager &buf_man, unsigned int lights_num) : BaseShader(device, hwnd), material_buf_(nullptr) { InitShader(buf_man, L"../shaders/light_alpha_map_vs.hlsl", L"../shaders/light_alpha_map_ps.hlsl", L"../shaders/tessellation_hs.hlsl", L"../shaders/light_ds.hlsl", lights_num); }
void init( void ) { vec3 vertices[4] = { vec3( 0.0, 0.0, -1.0 ), vec3( 0.0, 0.942809, 0.333333 ), vec3( -0.816497, -0.471405, 0.333333 ), vec3( 0.816497, -0.471405, 0.333333 ) }; // Subdivide the original tetrahedron divide_tetra( vertices[0], vertices[1], vertices[2], vertices[3], NumTimesToSubdivide ); // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); // First, we create an empty buffer of the size we need by passing // a NULL pointer for the data values glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors), NULL, GL_STATIC_DRAW ); // Next, we load the real data in parts. We need to specify the // correct byte offset for placing the color data after the point // data in the buffer. Conveniently, the byte offset we need is // the same as the size (in bytes) of the points array, which is // returned from "sizeof(points)". glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader24.glsl", "fshader24.glsl" ); glUseProgram( program ); // Initialize the vertex position attribute from the vertex shader GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); // Likewise, initialize the vertex color attribute. Once again, we // need to specify the starting offset (in bytes) for the color // data. Just like loading the array, we use "sizeof(points)" // to determine the correct value. GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) ); glEnable( GL_DEPTH_TEST ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); /* white background */ }
int main(int argc, char **argv) { colorcube(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitContextVersion( 3, 2 ); glutInitContextProfile( GLUT_CORE_PROFILE ); glutCreateWindow("colorcube"); glewExperimental = GL_TRUE; glewInit(); program = InitShader("vshader72.glsl", "fshader72.glsl"); init(); glutReshapeFunc(myReshape); glutDisplayFunc(display); glutIdleFunc(spinCube); glutMouseFunc(mouse); glutKeyboardFunc(key); glutMainLoop(); return 0; }
void setupData() { // build tree rebuildTree(); // matrices setView(); // create shader program GLuint sProgram = InitShader( "vert.glsl", "frag.glsl" ); // object buffer glGenBuffers( 1, &objectBuffer ); glBindBuffer( GL_ARRAY_BUFFER, objectBuffer ); // vertices vertLoc = glGetAttribLocation( sProgram, "a_vPosition" ); // indices glGenBuffers( 1, &indexBuffer ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer ); // texture coordinates //texCoordLoc = glGetAttribLocation( sProgram, "a_vTexCoord" ); // normals normalLoc = glGetAttribLocation( sProgram, "a_vNormal" ); // buffer to GPU sendData(); }
void shaderSetup1( void ) { // Load shaders and use the resulting shader program program = InitShader( "vshader1.glsl", "fshader1.glsl" ); glUseProgram( program ); // Initialize the vertex position attribute from the vertex shader GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); // sets white as color used to clear screen // Setting world window shit ProjLoc = glGetUniformLocation(program, "Proj"); // Default model matrix GLuint modelMatrix = glGetUniformLocationARB(program, "model_matrix"); glUniformMatrix4fv( modelMatrix, 1, GL_FALSE, mat4(1) ); // Default color setLineColor(RED_VEC); }
bool D3DTextureShader::Init(ID3D11Device* device, HWND hwnd) { bool result = InitShader(device, hwnd, L"Data/Shaders/texture.vs", L"Data/Shaders/texture.ps"); if (!result) return false; return true; }
// Metode per inicialitzar els shaders de l'aplicacio void GLWidget::initShadersGPU() { // Carrega dels shaders i posa a punt per utilitzar els programes carregats a la GPU //InitShader( "../Carreres/vshader11.glsl", "../Carreres/fshader11.glsl", program ); InitShader( "../Carreres/vshader12.glsl", "../Carreres/fshader12.glsl", program); }
void init( void ) { // Compute number of points in the ball and the total number of points for (int i = 0; i < divs; i++) numBallPoints *= 4; numPoints = numWallPoints + numBallPoints; // Allocate the arrays for the points and the colors point4 *points = new point4[numPoints]; color4 *colors = new color4[numPoints]; // Set up the wall cube( points, 0 ); randomColors( numWallPoints, colors, 0, // blue-black color4( 0.0, 0.0, 0.0, 1.0 ), color4( 0.1, 0.1, 0.3, 1.0 ) ); // Set up the ball spherichedron( divs, points, numWallPoints ); randomColors( numBallPoints, colors, numWallPoints, // bright red color4( 0.8, 0.0, 0.0, 1.0 ), color4( 1.0, 0.2, 0.1, 1.0 ) ); // Create a vertex array object GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, numPoints * (sizeof(point4) + sizeof(color4)), NULL, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, numPoints * sizeof(point4), points ); glBufferSubData( GL_ARRAY_BUFFER, numPoints * sizeof(point4), numPoints * sizeof(color4), colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "pingPong_vs.glsl", "pingPong_fs.glsl" ); glUseProgram( program ); // Initialize the vertex position attribute from the vertex shader GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(numPoints * sizeof(point4)) ); model_view = glGetUniformLocation( program, "model_view" ); glEnable( GL_DEPTH_TEST ); glClearColor( 1.0, 0.9, 0.75, 1.0 ); // light yellow background }
bool Shader::Init(ID3D11Device* device, HWND hwnd, LPCSTR* vsFilename, LPCSTR* psFilename, int shaderType) { bool result = 0; // Initialize the vertex and pixel shaders. // If it is a color shader if (shaderType == 0) { result = InitColorShader(device, hwnd, vsFilename, psFilename); } // If it is a ambient light shader else if (shaderType == 1) { const LPCSTR vsFunctionName = (LPCSTR)"AmbientLightVertexShader"; const LPCSTR psFunctionName = (LPCSTR)"AmbientLightPixelShader"; result = InitShader(device, hwnd, vsFilename, psFilename, &vsFunctionName, &psFunctionName, shaderType); } // If it is an specular light shader else if (shaderType == 2) { const LPCSTR vsFunctionName = (LPCSTR)"SpecularLightVertexShader"; const LPCSTR psFunctionName = (LPCSTR)"SpecularLightPixelShader"; result = InitShader(device, hwnd, vsFilename, psFilename, &vsFunctionName, &psFunctionName, shaderType); } // If it is a color & ambient light shader else if (shaderType == 3) { const LPCSTR vsFunctionName = (LPCSTR)"ColorAmbientLightVertexShader"; const LPCSTR psFunctionName = (LPCSTR)"ColorAmbientLightPixelShader"; result = InitShader(device, hwnd, vsFilename, psFilename, &vsFunctionName, &psFunctionName, shaderType); } // If it is a texture shader else if (shaderType == 4) { const LPCSTR vsFunctionName = (LPCSTR)"TextureVertexShader"; const LPCSTR psFunctionName = (LPCSTR)"TexturePixelShader"; result = InitShader(device, hwnd, vsFilename, psFilename, &vsFunctionName, &psFunctionName, shaderType); } if(!result) { return false; } return true; }
GLMiddleman::GLMiddleman() { program = InitShader( "vshader.glsl", "fshader.glsl" ); glUseProgram( program ); //grab pointers for our modelview and perspective uniform matrices model_view = glGetUniformLocation(program, "model_view"); projection = glGetUniformLocation(program, "projection"); }
void RPG_HighlightableComponentManager::InitShaders() { if(Vision::Shaders.LoadShaderLibrary("\\Shaders\\RPG.ShaderLib")) { m_xrayTechnique = Vision::Shaders.CreateTechnique("EntityXRay", NULL); if(m_xrayTechnique) { InitShader(m_xrayTechnique, m_xrayPassColorRegisters); } m_highlightTechnique = Vision::Shaders.CreateTechnique("EntityHighlight", NULL); if(m_highlightTechnique) { InitShader(m_highlightTechnique, m_highlightPassColorRegisters); } } }
// OpenGL initialization void init() { // Vertices of a unit cube centered at origin, sides aligned with axes vec4 points[6] = { vec4( -0.5, -0.5, 0, 1.0 ), //v1 vec4( 0.5, -0.5, 0, 1.0 ), //v2 vec4( -0.5, 0.5, 0, 1.0 ), //v3 vec4( -0.5, 0.5, 0, 1.0 ), //v3 vec4( 0.5, -0.5, 0, 1.0 ), //v2 vec4( 0.5, 0.5, 0, 1.0 ) //v4 }; // RGBA colors vec4 colors[6] = { vec4( 1.0, 0.0, 0.0, 1.0 ), // red vec4( 1.0, 0.0, 0.0, 1.0 ), // red vec4( 1.0, 0.0, 0.0, 1.0 ), // red vec4( 0.0, 1.0, 0.0, 1.0 ), // green vec4( 0.0, 1.0, 0.0, 1.0 ), // green vec4( 0.0, 1.0, 0.0, 1.0 ) // green }; // Create a vertex array object GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors), NULL, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader_translate.glsl", "fshader_translate.glsl" ); glUseProgram( program ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) ); // The location of the shader uniform variable "deltaT" locT = glGetUniformLocation( program, "translation" ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); }
int init( void ) { // general settings srand( time( NULL ) ); glClearColor( skyColor.x, skyColor.y, skyColor.z, 1.0 ); glEnable( GL_DEPTH_TEST ); glEnable( GL_TEXTURE_3D ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glPixelStorei( GL_PACK_ALIGNMENT, 1 ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); // set up data and shaders for( int y = 0; y < 3; ++y ) { for( int x = 0; x < 3; ++x ) { newMesh( x, y, LEFT | DOWN ); } } for( int y = 0; y < 3; ++y ) // normals must be calculated AFTER all vertices are set { for( int x = 0; x < 3; ++x ) { createMeshNormals( x, y ); } } resetView(); shaderProgram = InitShader( "vert.glsl", "frag.glsl" ); // buffer vertex and index data glGenBuffers( 9, (GLuint*)pointBuffer ); glGenBuffers( 9, (GLuint*)indexBuffer ); for( int x = 0; x < 3; ++x ) { for( int y = 0; y < 3; ++y ) { bufferData( x, y ); } } // create ground texture createAndBufferTexture(); // connect vertex attributes vPositionLoc = glGetAttribLocation( shaderProgram, "a_vPosition" ); glEnableVertexAttribArray( vPositionLoc ); vNormalLoc = glGetAttribLocation( shaderProgram, "a_vNormal" ); glEnableVertexAttribArray( vNormalLoc ); // get location of uniforms maxHeightLoc = glGetUniformLocation( shaderProgram, "u_fMaxHeight" ); mvMatrixLoc = glGetUniformLocation( shaderProgram, "u_mv_Matrix" ); glUniform1f( maxHeightLoc, maxHeight ); return 1; }
bool ShadowMapClass::Init(ID3D11Device* pDevice, float w, float h) { bool result; result = InitShader(pDevice, L"data/shaders/ShadowmapVS.hlsl", NULL, NULL, w, h);// L"data/shaders/ShadowmapPS.hlsl", L"data/shaders/ShadowmapGS.hlsl", w, h); if (!result) return false; return true; }