Ejemplo n.º 1
0
void GLWidget::initializeGL()
{
    //load opengl functions that are not in QGLFunctions
    //on mac and linux use glXGetProcAddress
    //on windows use wglGetProcAddress and don't cast to const GLubyte*
    initializeDraw();
    draw();
}
Ejemplo n.º 2
0
void Image::show(const char * title)
{
    GLFWwindow * pWindow = NULL;
    if (title != NULL)
    {
        fprintf(stderr, "Showing image %s.\n", title);
        pWindow = InitializeGLFWWindow(_width,
                                        _height,
                                        title);
    } else
    {
        fprintf(stderr, "Showing image.\n");
        pWindow = InitializeGLFWWindow(_width,
                                        _height,
                                        "Image");
        }

    glfwSetKeyCallback(pWindow, key_callback);

    //After the openGL context is set up, initialize openGL
    initializeDraw();

    //Then load data into a texture
    {
        glGenTextures(1, &GLInfo._tex);
        glBindTexture(GL_TEXTURE_2D, GLInfo._tex);
        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_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _width,
                               _height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                               _buf);
        GLuint tex_id = glGetUniformLocation(GLInfo._pid, "tex");
        glUniform1i(tex_id, 0 /*GL_TEXTURE0*/);
    }

    glUseProgram(GLInfo._pid);
    glBindVertexArray(GLInfo._vao);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, GLInfo._tex);

    //ok we're ready. Let glfw do the msg loop and draw the quad
    while (!glfwWindowShouldClose(pWindow))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        glfwSwapBuffers(pWindow);
        glfwPollEvents();
    }

     /// Close OpenGL window and terminate GLFW
    glfwDestroyWindow(pWindow);
    cleanupDraw();
    glfwTerminate();
}
Ejemplo n.º 3
0
		void BaseShapeUI::draw( const MDrawRequest & request, M3dView & view ) const {
			if (s_drawData.failure)
				return;

			MStatus status;

			view.beginGL();

			if (!s_drawData.initialized)
				initializeDraw();

			BaseShape *shape = (BaseShape *) surfaceShape();

			Model::Base base(MFnDagNode(shape->thisMObject()).parent(0, &status));

			if (!status) {
				status.perror("MFnDagNode::parent");
				return;
			}

			//MDagPath path = request.multiPath();
			MMaterial material = request.material();
			MColor color, borderColor;

			if (!(status = material.getDiffuse(color))) {
				status.perror("MMaterial::getDiffuse");
				return;
			}

			bool wireframe = (M3dView::DisplayStyle) request.token() == M3dView::kWireFrame;

			if (wireframe) {
				glPushAttrib(GL_POLYGON_BIT);

				glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
			}

			glUseProgram(s_drawData.program);
			
			switch (request.displayStatus())
            {
            case M3dView::kLead :
				borderColor = view.colorAtIndex( LEAD_COLOR);
				//glUniform1f(s_drawData.border_uniform, 1.0f);
				s_drawData.updateBorderUniform(1.0f);
				//glUniform3f(s_drawData.borderColor_uniform, borderColor.r, borderColor.g, borderColor.b);
				s_drawData.updateBorderColorUniform(borderColor.r, borderColor.g, borderColor.b);
				break;
            case M3dView::kActive :
                borderColor = view.colorAtIndex( ACTIVE_COLOR);
				//glUniform1f(s_drawData.border_uniform, 1.0f);
				s_drawData.updateBorderUniform(1.0f);
				//glUniform3f(s_drawData.borderColor_uniform, borderColor.r, borderColor.g, borderColor.b);
				s_drawData.updateBorderColorUniform(borderColor.r, borderColor.g, borderColor.b);
                break;
            case M3dView::kActiveAffected :
                borderColor = view.colorAtIndex( ACTIVE_AFFECTED_COLOR);
				//glUniform1f(s_drawData.border_uniform, 0.0f);
				s_drawData.updateBorderUniform(0.0f);
                break;
            case M3dView::kDormant :
				borderColor = view.colorAtIndex( DORMANT_COLOR, M3dView::kDormantColors);
				//glUniform1f(s_drawData.border_uniform, 0.0f);
				s_drawData.updateBorderUniform(0.0f);
                break;
            case M3dView::kHilite :
                borderColor = view.colorAtIndex( HILITE_COLOR);
				//glUniform1f(s_drawData.border_uniform, 1.0f);
				s_drawData.updateBorderUniform(1.0f);
				//glUniform3f(s_drawData.borderColor_uniform, borderColor.r, borderColor.g, borderColor.b);
				s_drawData.updateBorderColorUniform(borderColor.r, borderColor.g, borderColor.b);
                break;
            }

			//glUniform3f(s_drawData.color_uniform, color.r, color.g, color.b);
			s_drawData.updateColorUniform(color.r, color.g, color.b);

			glCallList(s_drawData.display_list);

			if (wireframe)
				glPopAttrib();

			view.endGL();
		}
Ejemplo n.º 4
0
void Image::show(const char * title)
{
	fprintf(stderr, "Showing image %s.\n", title);
	glfwSetErrorCallback(error_char);
    if (!glfwInit()) return;
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    GLFWwindow * pWindow = NULL;
    if (title == 0)
        pWindow = glfwCreateWindow(_width, _height, "Image", NULL, NULL);
    else
        pWindow = glfwCreateWindow(_width, _height, title, NULL, NULL);    

    if (!pWindow)
    {
        fprintf(stderr, "\nGLFW Window creation failed.\n");
        glfwTerminate();
        return;
    } else
    {
        
        int major, minor, rev;
        glfwMakeContextCurrent(pWindow);

#ifdef WIN_COMPILE
        glewExperimental=GL_TRUE; 
        if (glewInit() != GLEW_OK)
        {
            fprintf(stderr, "GLEW initialization failed.\n");
            return;
        }
#endif
        glfwGetVersion(&major, &minor, &rev);
        fprintf(stderr, "OpenGL version recieved: %d.%d.%d.\n", major, minor, rev);
    }
    
    glfwSwapInterval(1);
    glfwSetKeyCallback(pWindow, key_callback);

    //After the openGL context is set up, initialize openGL
    initializeDraw();

    //Then load data into a texture
    {
        glGenTextures(1, &GLInfo._tex);
        glBindTexture(GL_TEXTURE_2D, GLInfo._tex);
        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_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _width,
                               _height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                               _buf);
        GLuint tex_id = glGetUniformLocation(GLInfo._pid, "tex");
        glUniform1i(tex_id, 0 /*GL_TEXTURE0*/);
    }

    glUseProgram(GLInfo._pid);
    glBindVertexArray(GLInfo._vao);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, GLInfo._tex);

    //ok we're ready. Let glfw do the msg loop and draw the quad
    while (!glfwWindowShouldClose(pWindow))
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        glfwSwapBuffers(pWindow);
        glfwPollEvents();
    }

     /// Close OpenGL window and terminate GLFW
    glfwDestroyWindow(pWindow);
    cleanupDraw();
    glfwTerminate();
}