INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT) { WNDCLASSEX wc={sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "DX Project 1", NULL}; RegisterClassEx(&wc); HWND hWnd=CreateWindow("DX Project 1", "挺进3D", WS_OVERLAPPEDWINDOW, 50, 50, 500, 500, GetDesktopWindow(), NULL, wc.hInstance, NULL); if(hWnd==NULL) return FALSE; if(SUCCEEDED(InitializeD3D(hWnd))) { ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); if(SUCCEEDED(InitializeVertexBuffer())) { g_pFont=new CFont(g_pD3DDevice, "宋体", 12, true, false, false); GameLoop(); delete g_pFont; } } CleanUp(); UnregisterClass("DX Project 1", wc.hInstance); return 0; }
void initialize_opengl(CGLContextObj cgl_ctx) { InitializeVertexBuffer(); InitializeProgram(); glGenVertexArrays(1, &vertex_array_object); glBindVertexArray(vertex_array_object); }
void init() { InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); }
GlHelper::GlHelper() { float vertexPositions[] = { -0.5f, -0.5f, 0.5f, 1.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f }; float vertexColors[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }; xOffset = 0.0f; yOffset = 0.0f; std::copy(vertexPositions,vertexPositions + 12, this->vertexPositions); std::copy(vertexColors,vertexColors + 12, this->vertexColors); InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); }
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop. void init() { InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); size_t colorDataOffset = sizeof(float) * 3 * numberOfVertices; glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)colorDataOffset); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject); glBindVertexArray(0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LESS); glDepthRange(0.0f, 1.0f); }
PointLightPositionRenderer::PointLightPositionRenderer() : Renderers::IcosahedronRendererBase() { InitializeVertexBuffer(); LoadShaders(mShader, "shaders/IcosahedronShader.PointLight.gs.glsl", "shaders/IcosahedronShader.PointLight.forward.fs.glsl"); InitializeUniforms(mShader); LoadShaders(mWireFrameShader, "shaders/IcosahedronShader.PointLight.gs.glsl", "shaders/IcosahedronShader.WireFrame.forward.fs.glsl"); InitializeUniforms(mWireFrameShader); mIsInitialized = true; }
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop. void init() { InitializeProgram(); InitializeVertexBuffer(); InitializeVertexArrayObjects(); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); }
SpotLightPositionRenderer::SpotLightPositionRenderer(GLuint numStrips) : Renderers::ConeRendererBase() { InitializeVertexBuffer(numStrips); LoadShaders(mShader, "shaders/ConeShader.Light.gs.glsl", "shaders/ConeShader.Light.forward.fs.glsl"); InitializeUniforms(mShader); LoadShaders(mWireFrameShader, "shaders/ConeShader.Light.gs.glsl", "shaders/IcosahedronShader.WireFrame.forward.fs.glsl"); InitializeUniforms(mWireFrameShader); mIsInitialized = true; }
void init() { InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); }
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop. void tut1::OnPaintInit() { m_managerShader.AddShader( GL_VERTEX_SHADER, strVertexShader ); m_managerShader.AddShader( GL_FRAGMENT_SHADER, strFragmentShader ); m_managerShader.InitializeProgram( m_idProgram ); InitializeVertexBuffer(); glGenVertexArrays(1, &m_vao); glBindVertexArray(m_vao); }
void Window::Initialize() { D3D_FEATURE_LEVEL level; HRESULT hr = D3D11CreateDevice(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, 0, 0, D3D11_SDK_VERSION, &_d3dDevice, &level, &_d3dDeviceContext); Resize(); InitializeVertexBuffer(); InitializeShaders(); }
//Called whenever a key on the keyboard was pressed. //The key is given by the ''key'' parameter, which is in ASCII. void keyboard(unsigned char key, int x, int y) { // when a user hits one of these keys, change the global variable to that mode and // force a redraw with glutPostRedisplay switch (key) { case 'l': my_draw_mode = GL_LINES; glutPostRedisplay(); break; case 'p': my_draw_mode = GL_POINTS; glutPostRedisplay(); break; case 't': my_draw_mode = GL_TRIANGLES; glutPostRedisplay(); break; //switch betwee the 2 models (or reload a modified model) case 'q': readFile("data/bench.obj.flat.txt"); InitializeVertexBuffer(); break; case 'w': readFile("data/warehouse_model.dae.flat.txt"); InitializeVertexBuffer(); break; /* case 'f': if(my_fill_mode == GL_LINE) my_fill_mode = GL_FILL; else my_fill_mode = GL_LINE; glutPostRedisplay(); break; */ default: ;//nothing } }
//Called after the window and OpenGL are initialized. Called exactly once, before the main loop. void init() { readFile("data/bench.obj.flat.txt"); InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glutSetWindowTitle("K0858752 Assignment 4"); //init mouse functions glutMouseFunc(mouse); glutMotionFunc(mouseMove); }
void init() { InitializeProgram(); InitializeVertexBuffer(); InitializeVertexArrayObjects(); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); }
int main(int argc, char *args[]) { m_window = NULL; if (SDL_Init(SDL_INIT_VIDEO) == 0) { m_window = SDL_CreateWindow( WINDOW_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL ); init_opengl_context(m_window); InitializeVertexBuffer(); InitializeProgram(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); float a = 0; float fScaleAddition = 0.f; while (m_running){ SDL_Event ev; while (SDL_PollEvent(&ev)) { if (ev.type == SDL_QUIT) m_running = false; else if (ev.type == SDL_KEYDOWN) { glUseProgram(theProgram); if (ev.key.keysym.sym ==SDLK_UP){ fScaleAddition += 0.1f; } else if (ev.key.keysym.sym == SDLK_DOWN) { fScaleAddition -= 0.1f; } glUniform1f(frustumScaleUnif, 1.0f+fScaleAddition); glUseProgram(0); } } draw(a); } } // Your code here return 0; }
GlHelper::GlHelper() { float vertexPositions[] = { 0.25f, 0.25f, 0.0f, 1.0f, 0.25f, -0.25f, 0.0f, 1.0f, -0.25f, -0.25f, 0.0f, 1.0f, }; std::copy(vertexPositions,vertexPositions + 12, this->vertexPositions); InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); }
void NativeApplication::OpenGLInit(HWND wnd, HDC deviceContext, HGLRC renderingContext) { // GL thread class had loaded dummy context if (!gl.LoadOpenGLES2Functions()) throw NativeException("OpenGLES2 function loading failed"); hwnd = wnd; m_deviceContext = deviceContext; m_renderingContext = renderingContext; if (!ContextUtil::DestroyDummyAndCreateRealContext(gl, hwnd, &m_deviceContext, &m_renderingContext)) return; std::vector<GLuint> shaderList; try { shaderList.push_back(ShaderUtil::LoadAndCompileShader(GL_VERTEX_SHADER, "..\\NativeApp\\shaders\\LocalTransform.vert")); shaderList.push_back(ShaderUtil::LoadAndCompileShader(GL_FRAGMENT_SHADER, "..\\NativeApp\\shaders\\StandardColors.frag")); theProgram = ShaderUtil::CreateProgram(shaderList); } catch(NativeException&) { throw; } offsetUniform = glGetUniformLocation(theProgram, "offset"); modelMatrixUnif = glGetUniformLocation(theProgram, "modelMatrix"); perspectiveMatrixUnif = glGetUniformLocation(theProgram, "perspectiveMatrix"); CalculatePerspectiveMatrix(); glUseProgram(theProgram); glUniformMatrix4fv(perspectiveMatrixUnif, 1, GL_FALSE, perspectiveMatrix); glUseProgram(0); InitializeVertexBuffer(); // VAO is necessary when using core profile, unless code is run using NVidia card. At least, that's how I understood this obscure subject. // see https://www.opengl.org/discussion_boards/showthread.php/181092-Drawing-a-single-point-without-VAO-on-NVIDIA-and-AMD gl.glGenVertexArrays(1, &vao); gl.glBindVertexArray(vao); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); }
int main (int argc, char **argv) { glutInit (&argc, argv); glutInitWindowPosition (0, 0);/* position initiale */ glutInitWindowSize (640, 480);/* taille initiale fenetre graphique */ glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);/* affichage couleur */ /* Definit le type de fenetre d'affichage par composition des constantes suivantes: - GLUT_RGBA ou GLUT_INDEX (vraies couleurs ou couleurs indexées), - GLUT_SINGLE ou GLUT_DOUBLE (simple ou double buffer), - GLUT_DEPTH, GLUT_STENCIL (utilisation de tampons profondeur, stencil).*/ if (glutCreateWindow ("Initiation a OpenGL") <= 0)/* creation de la fenetre graphique */ { fprintf (stderr, "Impossible de creer la fenetre Glut.\n"); exit(EXIT_FAILURE); } // Setup GLEW GLenum err = glewInit(); if(GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } glClearColor (0.5, 0.5, 0.5, 1.0); /* definition de la couleur d'effacement (GL_COLOR_BUFFER_BIT) */ InitializeVertexBuffer(); glutDisplayFunc (&displayFunc);/* fonction d'affichage */ glutIdleFunc(&displayFunc); glutKeyboardFunc (&keyboardFunc); /* gestion du clavier */ glutMainLoop ();/* lancement de la boucle principale */ return EXIT_SUCCESS; }
OpenGLVertexBuffer::OpenGLVertexBuffer( const std::vector<Vertex>& vertices ) { InitializeVertexBuffer( vertices, GL_STATIC_DRAW ); }
GlHelper::GlHelper() { float vertexPositions[] = { +0.05f, +0.05f, -1.95f, 1.0f, -0.05f, -0.05f, -1.95f, 1.0f, -0.05f, +0.05f, -2.15f, 1.0f, +0.05f, -0.05f, -2.15f, 1.0f, -0.05f, -0.05f, -2.15f, 1.0f, +0.05f, +0.05f, -2.15f, 1.0f, +0.05f, -0.05f, -1.95f, 1.0f, -0.05f, +0.05f, -1.95f, 1.0f, }; float vertexColors[] = { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.0f, 1.0f, }; unsigned short vertexIndex[] = { 0, 1, 2, 1, 0, 3, 2, 3, 0, 3, 2, 1, 5, 4, 6, 4, 5, 7, 7, 6, 4, 6, 7, 5, }; xOffset = 0.0f; yOffset = 0.0f; std::copy(vertexPositions,vertexPositions + 8*4, this->vertexPositions); std::copy(vertexColors,vertexColors + 8*4, this->vertexColors); std::copy(vertexIndex,vertexIndex + 8*3, this->vertexIndex); float fFrustumScale=2.4f, zFar=3.0f, zNear=1.0f; memset(perspectiveMatrix,0,16*sizeof(float)); perspectiveMatrix[0]=fFrustumScale; perspectiveMatrix[5]=fFrustumScale; perspectiveMatrix[10]= (zFar + zNear) / (zNear - zFar); perspectiveMatrix[14]= (2*zFar * zNear) / (zNear - zFar); perspectiveMatrix[11]= -1.0f; memset(translateMatrix,0,16*sizeof(float)); translateMatrix[0] = 1.0f; translateMatrix[5] = 1.0f; translateMatrix[10]= 1.0f; translateMatrix[12]= 0.0f; translateMatrix[13]= 0.0f; translateMatrix[14]= 0.0f; translateMatrix[15]= 1.0f; memset(translateMatrix2,0,16*sizeof(float)); translateMatrix2[0] = 1.0f; translateMatrix2[5] = 1.0f; translateMatrix2[10]= 1.0f; translateMatrix2[12]= -0.30f; translateMatrix2[13]= 0.0f; translateMatrix2[14]= 0.0f; translateMatrix2[15]= 1.0f; memset(translateMatrix3,0,16*sizeof(float)); translateMatrix3[0] = 1.0f; translateMatrix3[5] = 1.0f; translateMatrix3[10]= 1.0f; translateMatrix3[12]= +0.30f; translateMatrix3[13]= 0.0f; translateMatrix3[14]= 0.0f; translateMatrix3[15]= 1.0f; InitializeProgram(); InitializeVertexBuffer(); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject); glBindVertexArray(0); glDisable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); }