小编gen*_*ult的帖子

如何在C++中使用GLUT/OpenGL绘制文本?

如何使用GLUT/OpenGL绘图功能在屏幕上绘制文本字符串?

c++ opengl text glut

23
推荐指数
3
解决办法
8万
查看次数

如何在同一布局中使用多个GLSurfaceView组件?

我正在为Android编写信息可视化API,并试图将两个自定义单元GLSurfaceView放入布局中遇到问题.此时的Custom GLSurfaceView只是一个扩展,GLSurfaceView以消除自定义方法可能导致的故障.

当我在布局中添加了两个组件并启动它运行的应用程序时.但没有任何东西被绘制,似乎它进入了一个无限循环.因为Renderers中的调试消息被打印到LogCat中.但是,如果我只使用其中一个自定义GLSurfaceView组件,它的工作完全正常.

我读到GLSurfaceView在多个活动中使用时出现问题,我想在同时使用其中两个组件时也适用.我已经尝试过这里发布的解决方法,但似乎无法让它工作.

我将不胜感激任何帮助.我选择使用openGL以获得更好的性能,但如果我不能同时使用多个组件,我想我将不得不使用Canvas.

清单如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:text="@string/hello" android:id="@+id/TextView01"
        android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    <com.syntronic.vtadlib.VisualizationView android:id="@+id/glview"
        android:layout_width="fill_parent" android:layout_height="300px" />


    <TextView android:text="@string/hello" android:id="@+id/TextView02"
        android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    <LinearLayout 
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <com.syntronic.vtadlib.VisualizationView android:id="@+id/glview2"
            android:layout_width="fill_parent" android:layout_height="fill_parent" />

    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

从Activity中,代码如下:

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    mSurfaceView = (VisualizationView) findViewById(R.id.glview);
    mSurfaceView2 = (VisualizationView) findViewById(R.id.glview2);

    //Enables debug flags for Errors
    //mSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);   
    //mSurfaceView2.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);  

    mSurfaceView.setRenderer(new …
Run Code Online (Sandbox Code Playgroud)

android opengl-es glsurfaceview android-layout

23
推荐指数
2
解决办法
9203
查看次数

iOS CVImageBuffer使用AVCaptureSessionPresetPhoto从AVCaptureSessionDataOutput失真

在高层次上,我创建了一个应用程序,让用户可以指向他或她的iPhone相机并查看已经过视觉效果处理过的视频帧.此外,用户可以点击按钮将当前预览的定格作为保存在其iPhone库中的高分辨率照片.

为此,该应用程序遵循以下过程:

1)创建AVCaptureSession

captureSession = [[AVCaptureSession alloc] init];
[captureSession setSessionPreset:AVCaptureSessionPreset640x480];
Run Code Online (Sandbox Code Playgroud)

2)使用后置摄像头连接AVCaptureDeviceInput.

videoInput = [[[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error] autorelease];
[captureSession addInput:videoInput];
Run Code Online (Sandbox Code Playgroud)

3)将AVCaptureStillImageOutput连接到会话,以便能够以Photo分辨率捕获静止帧.

stillOutput = [[AVCaptureStillImageOutput alloc] init];
[stillOutput setOutputSettings:[NSDictionary
    dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
    forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
[captureSession addOutput:stillOutput];
Run Code Online (Sandbox Code Playgroud)

4)将AVCaptureVideoDataOutput连接到会话,以便能够以较低分辨率捕获单个视频帧(CVImageBuffers)

videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
[videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
[captureSession addOutput:videoOutput];
Run Code Online (Sandbox Code Playgroud)

5)在捕获视频帧时,将每个新帧作为CVImageBuffer调用委托的方法:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    [self.delegate processNewCameraFrame:pixelBuffer];
}
Run Code Online (Sandbox Code Playgroud)

6)然后委托处理/绘制它们:

- (void)processNewCameraFrame:(CVImageBufferRef)cameraFrame {
    CVPixelBufferLockBaseAddress(cameraFrame, 0);
    int bufferHeight = CVPixelBufferGetHeight(cameraFrame);
    int bufferWidth = CVPixelBufferGetWidth(cameraFrame);

    glClear(GL_COLOR_BUFFER_BIT);

    glGenTextures(1, …
Run Code Online (Sandbox Code Playgroud)

iphone opengl-es image-processing ios opengl-es-2.0

23
推荐指数
2
解决办法
1万
查看次数

如何动态操纵纹理内容?

我有一个我正在研究的iPad应用程序,我们正在考虑的一个可能的功能是允许用户触摸图像并使其变形.

基本上,图像就像一幅画,当用户将手指拖过图像时,图像会变形,触摸的像素将沿着图像"拖动".很抱歉,如果这很难理解,但最重要的是我们想要在用户与之交互时动态编辑纹理的内容.

对于这样的事情,有没有一种有效的技术?我试图弄清楚需要做什么以及操作会有多重.

现在我唯一能想到的就是根据触摸的位置搜索纹理内容并复制像素数据,并在手指移动时对现有像素数据进行某种混合.然后定期用glTexImage2D重新加载纹理以获得此效果.

textures opengl-es ipad ios

22
推荐指数
2
解决办法
2万
查看次数

OpenGL:glGetError()在调用glewInit()后返回无效的枚举

我使用GLEW和freeglut.出于某种原因,在调用glewInit()之后,glGetError()返回错误代码1280,即使使用glewExperimental = GL_FALSE也是如此.

我无法编译着色器,glGetProgramInfoLog()返回"在调用glLinkProgram()之前未成功编译顶点着色器.链接失败." 之前我能够编译着色器.

重新安装驱动程序没有帮助.

这是我的代码:

int main(int argc, char* argv[])
{
    GLenum GlewInitResult, res;

    InitWindow(argc, argv);

    res = glGetError(); // res = 0

    glewExperimental = GL_TRUE;
    GlewInitResult = glewInit();    

    fprintf(stdout, "ERROR: %s\n", glewGetErrorString(GlewInitResult)); // "No error"
    res = glGetError(); // res = 1280

    glutMainLoop();

    exit(EXIT_SUCCESS);
}

void InitWindow(int argc, char* argv[])
{
    glutInit(&argc, argv);

    glutInitContextVersion(4, 0);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
    GLUT_ACTION_GLUTMAINLOOP_RETURNS);

    glutInitWindowPosition(0, 0);
    glutInitWindowSize(CurrentWidth, CurrentHeight);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

    WindowHandle = glutCreateWindow(WINDOW_TITLE);

    GLenum errorCheckValue = glGetError();

    if (WindowHandle …
Run Code Online (Sandbox Code Playgroud)

c++ opengl glew freeglut

22
推荐指数
1
解决办法
2万
查看次数

如果未绑定,是否在GLSL着色器中保留统一值?

我正在制作一个程序,它为不同的不同基元使用两个不同的着色器.我的问题是,如果我绑定一个程序,发送它统一变量,然后使用另一个着色器程序并回到第一个,传递的统一值是否仍然存在?这是一些伪代码:

glUseProgram(shader1);
glUniform(shader1,...);
//stuff

for(elements in a list) {
    if(element.type = 1) {
        glUseProgram(shader2);
        element.draw();
    } else {
        glUseProgram(shader1); //Here, do the uniforms from above remain, if shader2 was bound before?
        element.draw();
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ opengl glsl

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

使用Opencv检测图像中的文本区域

我有一个图像,想要检测其中的文本区域.

我试过TiRG_RAW_20110219项目,但结果并不理想.如果输入图像是http://imgur.com/yCxOvQS,GD38rCa,则它将生成http://imgur.com/yCxOvQS,GD38rCa#1作为输出.

谁能提出一些替代方案.我想通过仅将文本区域作为输入发送来改善tesseract的输出.

opencv python-2.7 python-tesseract

22
推荐指数
3
解决办法
4万
查看次数

GLSL中的多个纹理 - 只有一个有效

我的问题是在GLSL着色器中可以访问多个纹理.这是我正在做的事情:

着色器:

uniform sampler2D sampler0;
uniform sampler2D sampler1;
uniform float blend;
void main( void )
{
    vec2 coords = gl_TexCoord[0];
    vec4 col = texture2D(sampler0, coords);
    vec4 col2 = texture2D(sampler1, coords);
    if (blend > 0.5){
        gl_FragColor = col;
    } else {
        gl_FragColor = col2;
    }
};
Run Code Online (Sandbox Code Playgroud)

因此,我只需根据统一变量在两个颜色值之间进行选择.足够简单(这是一个测试),但是当混合<= 0.5时,我得到全黑,而不是预期的行为.

OpenGL代码:

m_sampler0location = m_shader.FindUniform("sampler0");
m_sampler1location = m_shader.FindUniform("sampler1");
m_blendlocation = m_shader.FindUniform("blend");

glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
m_extensions.glUniform1iARB(m_sampler0location, 0);
glBindTexture(GL_TEXTURE_2D, Texture0.Handle);  
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
m_extensions.glUniform1iARB(m_sampler1location, 1);
glBindTexture(GL_TEXTURE_2D, Texture1.Handle);
glBegin(GL_QUADS);
    //lower left
    glTexCoord2f(0, 0);
    glVertex2f(-1.0, -1.0);
    //upper left …
Run Code Online (Sandbox Code Playgroud)

opengl textures glsl

21
推荐指数
3
解决办法
4万
查看次数

GLSL gl_FragCoord.z计算和设置gl_FragDepth

所以,我有一个冒名顶替者(真正的几何体是一个立方体,可能被修剪,冒名顶的几何体是Menger海绵),我需要计算它的深度.

我可以相当容易地计算出在世界空间中抵消的金额.不幸的是,我花了好几个小时没有用它来扰乱深度.

我能得到的唯一正确结果是我去的时候:

gl_FragDepth = gl_FragCoord.z
Run Code Online (Sandbox Code Playgroud)

基本上,我需要知道如何计算gl_FragCoord.z,以便我可以:

  • 从gl_FragCoord.z到眼睛空间进行逆变换
  • 添加深度扰动
  • 将这个扰动的深度转换回与原始gl_FragCoord.z相同的空间.

如果这似乎是一个重复的问题,我道歉; 这里有很多其他帖子可以解决类似问题.但是,在实现所有这些之后,没有一个正常工作.而不是试图选择一个来获得帮助,此时,我要求完整的代码来完成它.它应该只是几行.

opengl shader glsl

21
推荐指数
2
解决办法
1万
查看次数

如何解决此错误:#include <gl/glut.h>"无法打开源文件gl/glut.h"

我在C++中做了一些OpenGL编程.

这是我的代码的一部分:

#include <time.h>
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h> <<< Error here "Cannot open source file gl/glut.h"
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

编辑:我正在使用Microsoft Visual C++ Express Edition.对不起忘了提它

c++ opengl vector matrix

21
推荐指数
2
解决办法
12万
查看次数