Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp to rectify line scaling in Android OpenGL 2.0 w/ QCAR
    primarykey
    data
    text
    <p>I'm working w/ the QCAR AR SDK in Android, which uses OpenGL 2.0, and I'm new to 2.0. The QCAR SDK is for CV based AR apps and utilizes OpenGL for rendering onto images.</p> <p>I'd simply like to draw a small X at the center of the screen, and am using the following code. But rather than draw an X to the correct coordinates, the X extends to the edges of the screen. This occurs regardless of what values I assign to the vertices. I can't make out if this is a scaling issue or some confusion in the coordinate system that I'm using.</p> <p>Any ideas as to why these lines aren't being drawn properly?? - I know that this would be easier in 1.1, but I've got to use 2.0.</p> <p>thnx</p> <pre><code>// Clear color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); GLfloat diagVertices[12]; diagVertices[0] = -10; diagVertices[1] = -10; diagVertices[2] = 0.0f; diagVertices[3] = 10; diagVertices[4] = 10; diagVertices[5] = 0.0f; diagVertices[6] = -10; diagVertices[7] = 10; diagVertices[8] = 0.0f; diagVertices[9] = 10; diagVertices[10] = -10; diagVertices[11] = 0.0f; glUseProgram(diagonalShaderProgramID); // map the border vertices glVertexAttribPointer(diagVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &amp;diagVertices[0]); // draw it glEnableVertexAttribArray(diagVertexHandle); glLineWidth(3.0f); glDrawArrays(GL_LINES, 0, 4); glDisableVertexAttribArray(diagVertexHandle); </code></pre> <p>Here's the shader that I'm using..</p> <pre><code>static const char* diagLineMeshVertexShader = " \ \ attribute vec4 vertexPosition; \ \ void main() \ { \ gl_Position = vertexPosition; \ } \ "; static const char* diagLineFragmentShader = " \ \ precision mediump float; \ \ void main() \ { \ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \ } \ "; </code></pre> <h1>Update:</h1> <p>So I've established a build environment in Windows 7 (64) using Eclipse and Cygwin, and have tested the same approach - drawing vertex attribute arrays. The codebase is derived from a simple lighthouse3D sample demonstrating GSLS. I'd compiled and run the sample to confirm that it's rendering as expected. Then I'd implemented vertex arrays, as above. I'm seeing exactly the same problem. The lines extend to the edges of the window regardless of their vertex values. </p> <p>This is for GL_VERSION 2.1.2. The implementation of vertex attribute arrays, and the method for rendering them, appears to be identical to other examples that I've found through reference resources. </p> <p>Here's the code.. <em>- I've commented out the sections of lighthouse3d code that I've altered.</em></p> <pre><code>#define WIN32 #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;GL/Glee.h&gt; #include &lt;GL/glut.h&gt; #include "textfile.h" GLuint v,f,f2,p; float lpos[4] = {1,0.5,1,0}; GLfloat crossVertices[12]; GLint lineVertexHandle = 0; void changeSize(int w, int h) { // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if(h == 0) h = 1; float ratio = 1.0* w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); // Set the correct perspective. //gluPerspective(45,ratio,1,1000); gluPerspective(45,ratio,1,10); glMatrixMode(GL_MODELVIEW); } void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0.0,0.0,5.0, 0.0,0.0,0.0, 0.0f,1.0f,0.0f); glLightfv(GL_LIGHT0, GL_POSITION, lpos); //glutSolidTeapot(1); // map the border vertices glVertexAttribPointer(lineVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &amp;crossVertices[0]); glEnableVertexAttribArray(lineVertexHandle); glLineWidth(1.0f); glDrawArrays(GL_LINES, 0, 4); glDisableVertexAttribArray(lineVertexHandle); glutSwapBuffers(); } void processNormalKeys(unsigned char key, int x, int y) { if (key == 27) exit(0); } void setShaders() { char *vs = NULL,*fs = NULL,*fs2 = NULL; v = glCreateShader(GL_VERTEX_SHADER); f = glCreateShader(GL_FRAGMENT_SHADER); f2 = glCreateShader(GL_FRAGMENT_SHADER); vs = textFileRead("toon.vert"); fs = textFileRead("toon.frag"); fs2 = textFileRead("toon2.frag"); const char * ff = fs; const char * ff2 = fs2; const char * vv = vs; glShaderSource(v, 1, &amp;vv,NULL); glShaderSource(f, 1, &amp;ff,NULL); glShaderSource(f2, 1, &amp;ff2,NULL); free(vs);free(fs); glCompileShader(v); glCompileShader(f); glCompileShader(f2); p = glCreateProgram(); glAttachShader(p,f); glAttachShader(p,f2); glAttachShader(p,v); glLinkProgram(p); glUseProgram(p); } void defineVertices(){ crossVertices[0]= 10.0f; crossVertices[1]=0.0f; crossVertices[2]=0.0f; crossVertices[3]= -1 * 10.0f; crossVertices[4]=0.0f; crossVertices[5]=0.0f; crossVertices[6]=0.0f; crossVertices[7]= 10.0f; crossVertices[8]=0.0f; crossVertices[9]=0.0f; crossVertices[10]= -1 * 10.0f; crossVertices[11]=0.0f; } int main(int argc, char **argv) { glutInit(&amp;argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(320,320); glutCreateWindow("MM 2004-05"); glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutKeyboardFunc(processNormalKeys); glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,1.0); glEnable(GL_CULL_FACE); /* glewInit(); if (glewIsSupported("GL_VERSION_2_0")) printf("Ready for OpenGL 2.0\n"); else { printf("OpenGL 2.0 not supported\n"); exit(1); } */ setShaders(); defineVertices(); glutMainLoop(); // just for compatibiliy purposes return 0; } </code></pre> <p>and here is the vertex shader, which is from the lighthouse3D example...</p> <pre><code>varying vec3 normal, lightDir; void main() { lightDir = normalize(vec3(gl_LightSource[0].position)); normal = normalize(gl_NormalMatrix * gl_Normal); gl_Position = ftransform(); } </code></pre> <p>Any ideas on what's likely to be causing this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload