Iphone OpenGL Noob问题:绘图的起始位置

Iphone OpenGL Noob问题:绘图的起始位置,iphone,ios,animation,opengl-es,Iphone,Ios,Animation,Opengl Es,我有一条我正在绘制的线,但绘制的起点始终是容器视图的死点。我怎样才能使绘图恰好出现在视图右侧的内部 //Code - (void)drawView { // Replace the implementation of this method to do your own custom drawing GLfloat lineVertices[maxCurvePoint*2]; GLfloat lineVerticesGrid[GRID_LINES_HORZ*

我有一条我正在绘制的线,但绘制的起点始终是容器视图的死点。我怎样才能使绘图恰好出现在视图右侧的内部

//Code

- (void)drawView {


    // Replace the implementation of this method to do your own custom drawing




    GLfloat lineVertices[maxCurvePoint*2];
    GLfloat lineVerticesGrid[GRID_LINES_HORZ*GRID_LINES_VERT*4];
    GLfloat lineVerticesGridTexCoords[GRID_LINES_HORZ*GRID_LINES_VERT*4];
    float currLevel = curve[(maxCurvePoint+curveStart-1)%maxCurvePoint];

    int i;
    for (i=0; i<maxCurvePoint; i++) {
        lineVertices[i*2] = i/(maxCurvePoint/2.0)-1.0; // X
        lineVertices[i*2+1] = curve[(i+curveStart)%maxCurvePoint]; // Y
    }

    for (i=0; i<GRID_LINES_HORZ; i++) {
        float yval = 4.0*i/GRID_LINES_HORZ-2.0;
        lineVerticesGrid[i*4] = -2.0; // X
        lineVerticesGrid[i*4+1] = yval; // Y
        lineVerticesGrid[i*4+2] = 2.0; // X
        lineVerticesGrid[i*4+3] = yval; // Y
        lineVerticesGridTexCoords[i*4] = -2.3/1.4; // X
        lineVerticesGridTexCoords[i*4+1] = (yval-currLevel)/1.4; // Y
        lineVerticesGridTexCoords[i*4+2] = 1.7/1.4; // X
        lineVerticesGridTexCoords[i*4+3] = (yval-currLevel)/1.4+0.7; // Y
    }

    for (i=0; i<GRID_LINES_VERT; i++) {
        int j = (GRID_LINES_HORZ+i)*4; 
        float xval = 4.0*i/GRID_LINES_VERT-2.0;
        lineVerticesGrid[j] = 4.0*i/GRID_LINES_VERT-2.0; // X
        lineVerticesGrid[j+1] = -2.0; // Y
        lineVerticesGrid[j+2] = 4.0*i/GRID_LINES_VERT-2.0; // X
        lineVerticesGrid[j+3] = 2.0; // Y
        lineVerticesGridTexCoords[j] = (xval-0.7)/1.4; // X
        lineVerticesGridTexCoords[j+1] = currLevel/1.4+1.4+0.5; // Y
        lineVerticesGridTexCoords[j+2] = (xval-0.7)/1.4+0.7; // X
        lineVerticesGridTexCoords[j+3] = currLevel/1.4-1.4+0.5; // Y
    }

    [EAGLContext setCurrentContext:context];

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    //glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glScalef(0.8, 0.8, 1.0);
    glTranslatef(-0.2, 0, 0);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_TEXTURE_2D);

    glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2, GL_SHORT, 0, spriteTexcoords);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glPushMatrix();
    glTranslatef(1.0, currLevel, -0.01);


    glColor4f(0.0, 0.0, 0.0, 1.0); //SpotLight - Should be kinda light

    /*
    if([colorTheme isEqualToString:@"blue"]) //SpotLight - Should be kinda light
      glColor4f(0.0, 0.0, 0.0, 1.0); 
    else if ([colorTheme isEqualToString:@"red"])
      glColor4f(0.5, 0.0, 0.0, 1.0);  
    else if ([colorTheme isEqualToString:@"green"])
        glColor4f(0.0, 0.5, 0.0, 1.0);  
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 101/255.f, 3/255.f, 1.0); 
    else
        glColor4f(0.0, 0.0, 0.0, 1.0); */



    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glPopMatrix();

    glVertexPointer(2, GL_FLOAT, 0, lineVerticesGrid);
    glEnableClientState(GL_VERTEX_ARRAY);

    glTexCoordPointer(2, GL_FLOAT, 0, lineVerticesGridTexCoords);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glLineWidth(1.0);

    glColor4f(0.0, 0.0, 0.0, 1.0);//Grid Lines behind spotlight...Very faint

    /*
    if([colorTheme isEqualToString:@"blue"]) //Grid Lines behind spotlight...Very faint
          glColor4f(0.0, 0.0, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"red"])
          glColor4f(0.4, 0.0, 0.0, 1.0);    
    else if ([colorTheme isEqualToString:@"green"])
        glColor4f(0.0, 0.4, 0.0, 1.0);  
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 204/255.f, 7/255.f, 1.0); 
     else
        glColor4f(0.0, 0.0, 0.0, 1.0); */

    glDrawArrays(GL_LINES, 0, (GRID_LINES_HORZ+GRID_LINES_VERT)*2);

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);

    glVertexPointer(2, GL_FLOAT, 0, lineVertices);
    glEnableClientState(GL_VERTEX_ARRAY);

    glLineWidth(9.0);
    glPointSize(9.0);


    if([colorTheme isEqualToString:@"blue"])  //Wave line before cursor outside color... little faint
       glColor4f(0.0, 0.5, 1.0, 0.2); 
    else if ([colorTheme isEqualToString:@"red"])
        glColor4f(0.5, 0.0, 0.0, 0.2);      
    else if ([colorTheme isEqualToString:@"green"])
        glColor4f(0.0, 0.5, 0.0, 0.2); 
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 194/255.f, 12/255.f, 0.2); 
    else
        glColor4f(0.0, 0.0, 0.0, 1.0); 


    glDrawArrays(GL_LINE_STRIP, 0, maxCurvePoint);
    glTranslatef(0, 0, .01);
    glDrawArrays(GL_POINTS, 0, maxCurvePoint);
    glPointSize(15.0);
    glDrawArrays(GL_POINTS, maxCurvePoint-1, 1);

    glTranslatef(0, 0, .01);

    glLineWidth(3.0);
    glPointSize(3.0);


    //Wave line before cursor inside
    if([colorTheme isEqualToString:@"blue"])
        glColor4f(0.0, 0.5, 1.0, 0.7); 
    else if ([colorTheme isEqualToString:@"red"])
        glColor4f(0.5, 0.0, 1.0, 0.7);  
    else if ([colorTheme isEqualToString:@"red"])
        glColor4f(0.0, 0.5, 1.0, 0.7); 
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 220/255.f, 11/255.f, 0.7); 
    else
        glColor4f(0.0, 0.0, 0.0, 1.0); 


    glDrawArrays(GL_LINE_STRIP, 0, maxCurvePoint);
    glTranslatef(0, 0, .01);
    glDrawArrays(GL_POINTS, 0, maxCurvePoint);
    glPointSize(9.0);
    glDrawArrays(GL_POINTS, maxCurvePoint-1, 1);

    glTranslatef(0, 0, .01);

    glLineWidth(1.0);
    glPointSize(1.0);
    glColor4f(1.0, 1.0, 1.0, 1.0);
    glDrawArrays(GL_LINE_STRIP, 0, maxCurvePoint);
    glPointSize(5.0);
    glDrawArrays(GL_POINTS, maxCurvePoint-1, 1);

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

    if (demoMode){

        if (randomMode)
           curve[ curveStart ] =  ((rand()%32768)/32768.0)*0.4-0.2;
        else
            curve[ curveStart ] =  ekgMap[ curveStart ]; // ((rand()%32768)/32768.0)*0.4-0.2;
    //  DLog(@"%f", ekgMap[ curveStart ]);

     }  else{


         if ([dataPoints count] ==0){

             curve[ curveStart ] =  0.0;

         }else {

             if (!inverted) {

                 curve[curveStart] =  scaleByMid(self.min, self.max, [[dataPoints dequeue] floatValue]) /scaleFactor; //   [[dataPoints dequeue] floatValue] /scaleFactor;

                // DLog(@"Queue Length: %d", [dataPoints count]);

             } else{

                 float point = scaleByMid(self.min, self.max, [[dataPoints dequeue] floatValue]) /scaleFactor;
                 curve[curveStart] =  (point -(point *2));


             }
         }
    }

    curveStart = (curveStart+1)%maxCurvePoint;

}
//代码
-(无效)drawView{
//替换此方法的实现以进行自定义绘图
GLfloat linevertexts[maxCurvePoint*2];
GLfloat lineVerticesGrid[网格线水平*网格线垂直*4];
GLfloat lineVerticesGridTexCoords[GRID_LINES_HORZ*GRID_LINES_VERT*4];
浮动电流电平=曲线[(maxCurvePoint+curveStart-1)%maxCurvePoint];
int i;

对于(i=0;i在正交视图中,您正在将左侧和右侧设置为-1和1,类似地,顶部和底部设置为-1.5和1.5。将其修改为0表示宽度,将其修改为0表示高度,以获得左上角(或左下角,基于您使用的平台)的原点


glOrthof(0,宽度,0,高度,1100);

我不熟悉openGL,但是你能不能把你的X,Y值从0,0转换到你想要的地方?