• Advertisement

aevanthony

Member
  • Content count

    85
  • Joined

  • Last visited

Community Reputation

100 Neutral

About aevanthony

  • Rank
    Member
  1. the screen coordinates ranges from -1.0 to 1.0 for both axis. the center of the screen is 0.0.
  2. I'm going to look in to using a dynamic VBO, it'll be important for me to have the largest hardware support possible. Thanks a bunch for the tip! :)
  3. I've been attaching audio data to a texture in such a way that the final result is something akin to; [0][x][0][0][0] [0][0][0][0][0] [x][0][0][x][x] [0][0][x][0][0] [0][0][0][0][0] time:0 -> N (Sample Size; in my case 128x128 texture) where x = the amplitude of the audio signal at that time. This is obviously inefficient. So what do I do? I tried sending up a Nx1 size texture which is way better the only problem is, in the fragment shader I could never use the information to color fragments as I would prefer. ** edit: rephrased the question How do I graph the signal on to a 2D texture from a 1D texture in my fragment shader, using the values of the 1D texture as the data for the y-axis. Is that even possible? [Edited by - aevanthony on May 19, 2008 2:26:25 PM]
  4. Problem with multi-texturing [SOLVED]

    After a lot of searching I found some thread on this forum that made a reference to the necessity to call 'glPixelStorei()' before 'glTexSubImage2D()'. So I looked in to consideration and included as below. I also went with 'glTexSubImage2D()' instead of 'glTexImage2D()' I'm not sure if it was a combination of those, or some other small adjustments but 'glMultiTexCoord2fARB()' also works as expected. Here is only the updated portion of my render loop: // ... fmresult = FMOD_Channel_GetWaveData(fmchannel, fmLBuf, SAMPLESIZE, 0); fmresult = FMOD_Channel_GetWaveData(fmchannel, fmRBuf, SAMPLESIZE, 1); t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; for (int x=0; x<SD; ++x) for (int y=0; y<SD; ++y) { TexAudio[x][y][0] = fmLBuf[x]; TexAudio[x][y][1] = fmRBuf[y]; TexAudio[x][y][2] = GLfloat (0.0); TexAudio[x][y][3] = GLfloat (1.0); } glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_2D, FBOTex[TexAudioData]); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // <--- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SD, SD, GL_RGBA, GL_FLOAT, TexAudio); // <--- glUseProgramObjectARB(p); glActiveTextureARB(GL_TEXTURE0_ARB); vLoc = glGetUniformLocationARB(p, "dtex"); glUniform1iARB(vLoc, 0); glActiveTextureARB(GL_TEXTURE2_ARB); vLoc = glGetUniformLocationARB(p, "atex"); glUniform1iARB(vLoc, 2); vLoc = glGetUniformLocationARB(p, "aDi"); glUniform1fARB(vLoc, (float)SD); vLoc = glGetUniformLocationARB(p, "time"); glUniform1fARB(vLoc, t); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO); glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT); glViewport(0, 0, SD, SD); glDrawBuffer(AttchPoint[TexRenderRead]); glActiveTextureARB(GL_TEXTURE0_ARB + TexRenderRead); glPushMatrix(); glBegin(GL_QUADS); // <--- MultiTex instead of TexCoord... glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 0.0); glVertex2f(-1.0, -1.0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 1.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 1.0); glVertex2f(-1.0, 1.0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 1.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 1.0); glVertex2f( 1.0, 1.0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 0.0); glVertex2f( 1.0, -1.0); glEnd(); glPopMatrix(); // ...
  5. OpenGL Bit of a variable error (solved)

    Declare it like this with this value as a global var; const short BITMAP_ID = 19778; It'll work if "BITMAP_ID" is actually synonymous with what is used in the loader i use, and it appears to be based on what I see there. Here's a loader I prefer to use if you still have problems. const short BITMAP_MAGIC_NUMBER = 19778; const int RGB_BYTE_SIZE = 3; #pragma pack(push,bitmap_data,1) typedef struct tagRGBQuad { char rgbBlue; char rgbGreen; char rgbRed; char rgbReserved; } RGBQuad; typedef struct tagBitmapFileHeader { unsigned short bfType; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; } BitmapFileHeader; typedef struct tagBitmapInfoHeader { unsigned int biSize; int biWidth; int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; int biXPelsPerMeter; int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; } BitmapInfoHeader; #pragma pack(pop,bitmap_data) class Bitmap { public: RGBQuad *colours; char *data; bool loaded; int width, height; unsigned short bpp; int *rgb; Bitmap (); Bitmap (const char *); ~Bitmap (); bool loadBMP (const char *); void getPixel (int x, int y); private: BitmapFileHeader bmfh; BitmapInfoHeader bmih; int byteWidth; int padWidth; unsigned int dataSize; void reset(void); bool convert24 (char *); bool convert8 (char *); }; Bitmap::Bitmap() { reset(); } Bitmap::Bitmap(const char *file) { reset(); loadBMP(file); } Bitmap::~Bitmap() { if (colours!=0) { delete[] colours; } if (data!=0) { delete[] data; } } void Bitmap::getPixel(int x, int y) { delete[] rgb; rgb = new int[3]; int i = ((y * width) + x) * RGB_BYTE_SIZE; rgb[0] = *(data + i + 0); rgb[1] = *(data + i + 1); rgb[2] = *(data + i + 2); } bool Bitmap::loadBMP(const char *file) { FILE *in; char *tempData; int numColours; loaded = false; if (colours != 0) { delete[] colours; } if (data != 0) { delete[] data; } in = fopen(file,"rb"); if (in == NULL) { fclose(in); return false; } fread(&bmfh, sizeof(BitmapFileHeader), 1, in); if (bmfh.bfType != BITMAP_MAGIC_NUMBER) { fclose(in); return false; } fread(&bmih, sizeof(BitmapInfoHeader), 1, in); width = bmih.biWidth; height = bmih.biHeight; bpp = bmih.biBitCount; dataSize = width * height * RGB_BYTE_SIZE; numColours = (1 << bmih.biBitCount); if (bpp < 8) { fclose(in); return false; } if (bpp == 8) { colours = new RGBQuad[numColours]; fread(colours, sizeof(RGBQuad), numColours, in); } tempData = new char[dataSize]; if (tempData == NULL) { fclose(in); return false; } fread(tempData, sizeof(char), dataSize, in); fclose(in); byteWidth = padWidth = (int)((float)width * (float)RGB_BYTE_SIZE); while (padWidth%4 != 0) { ++padWidth; } if (bpp == 8) { loaded = convert8(tempData); } else if (bpp == 24) { loaded = convert24(tempData); } delete[] tempData; return loaded; } void Bitmap::reset(void) { loaded = false; colours = 0; data = 0; } bool Bitmap::convert24(char* tempData) { int offset, diff; diff = width * height * RGB_BYTE_SIZE; data = new char[diff]; if (data == NULL) { delete[] data; return false; } if (height > 0) { offset = padWidth - byteWidth; for (int i=0; i<dataSize; i+=RGB_BYTE_SIZE) { if ((i+1)%padWidth == 0) { i += offset; } *(data+i+2) = *(tempData+i+0); *(data+i+1) = *(tempData+i+1); *(data+i+0) = *(tempData+i+2); } } else { offset = padWidth - byteWidth; for (int i=0, j=dataSize-RGB_BYTE_SIZE; i<dataSize; i+=RGB_BYTE_SIZE, j-=3) { if ((i+1)%padWidth == 0) { i += offset; } *(data+j+2) = *(tempData+i+2); *(data+j+1) = *(tempData+i+1); *(data+j+0) = *(tempData+i+0); } } return true; } bool Bitmap::convert8(char* tempData) { int offset, diff; diff = width * height * RGB_BYTE_SIZE; data = new char[diff]; if (data == NULL) { delete[] data; return false; } if (height>0) { offset = padWidth - byteWidth; for (int i=0, j=0; i<dataSize*RGB_BYTE_SIZE; i+=RGB_BYTE_SIZE, ++j) { if ((i+1)%padWidth==0) { i += offset; } *(data+i) = colours[*(tempData+j)].rgbRed; *(data+i+1) = colours[*(tempData+j)].rgbGreen; *(data+i+2) = colours[*(tempData+j)].rgbBlue; } } else { offset = padWidth - byteWidth; for (int i=0, j=dataSize-1; i<dataSize*RGB_BYTE_SIZE; i+=RGB_BYTE_SIZE, --j) { if ((i+1)%padWidth==0) { i += offset; } *(data+i) = colours[*(tempData+j)].rgbRed; *(data+i+1) = colours[*(tempData+j)].rgbGreen; *(data+i+2) = colours[*(tempData+j)].rgbBlue; } } return true; } Use: Bitmap lbmp = new Bitmap("I16_full.bmp"); // lbmp->getPixel(x, y); // lbmp->width | height | etc
  6. Problem with multi-texturing [SOLVED]

    It seems I actually don't need to use 'glMultiTexCoord2fARB' at the moment, so I'm fine on that front. In my last post I should have mentioned I went back to just using 'glTexCoord2f' since 'glTexImage2D' seems to toss the pixel data up to the GPU (sort of it seems.), so I'm not rendering two textures, just one. But I've still been struggling with finding ways of getting all the pixel data I need to the GPU. /long-sigh I can't wait to get this over with, then I can finally focus on algorithms, my last bump in this learning curve is a damn CPU->GPU transfer for some audio data.
  7. Problem with multi-texturing [SOLVED]

    Sort of have it working. Instead of each texel representing it's own color value per audio data, I get a solid flickering image (flickering to the beat of the music, so at lease *one value is being sent....), any idea why? I'm clearly stating that for a texture of dimensions SDxSD (256x256 in this case) to assign a unique value from the audio buffer. Why would it render as if only one value is being sent, and if that's the case... what should I do? (in the vert shader: 'gl_TexCoord[1] = gl_MultiTexCoord2;') a portion of the RENDER sequence: //... for (int x=0; x<SD; ++x) for (int y=0; y<SD; ++y) { TexAudio[x][y][0] = GLubyte (int(fmLBuf[x] * 128) + 127); TexAudio[x][y][1] = GLubyte (int(fmRBuf[y] * 128) + 127); TexAudio[x][y][2] = 0; TexAudio[x][y][3] = 255; } glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_2D, FBOTex[TexAudioData]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, SD, SD, 0, GL_RGBA, GL_UNSIGNED_BYTE, TexAudio); // ... fbo stuff/quad/etc
  8. Problem with multi-texturing [SOLVED]

    Why would the results of; 'glTexCoord2f(...)' differ from; 'glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i,...)' ? It seems to be the case for me... I can't get the correct output with glMulti..., it looks like the two diagonal halves of the screen just flicker back and forth. Am I missing something with that?
  9. Problem with multi-texturing [SOLVED]

    I tried a few things different, but none of it seemed to work. At first I used the rendering sequence below on just FBO to Texture, then just to the window, and both... I figured you meant I had to do something like this to get the other texture to the GPU... But... like I said... the only thing this did was give me some choppy flickering. And only in the one color I was looping, regardless of what appeared since none of the color channels with the audio data came through in the image. So what's wrong with what I did, and what do I do? glBegin(GL_QUADS); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 1.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 1.0); glVertex3f(-1.0, 1.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 1.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 1.0); glVertex3f( 1.0, 1.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 0.0); glVertex3f( 1.0, -1.0, 0.0); glEnd();
  10. Problem with multi-texturing [SOLVED]

    The source was the often cited Lighthouse3d website. But I understand what you're saying. Gotcha. With all the considerations in your reply I've made some more necessary adjustments. Except one... So what I need to do is render the audio data to some off screen quad and just never display it? Or is there some better way of "rendering" the data so it goes to the GPU? I'm not sure how to go about this ... How do I get the data to the gpu, exactly? :) I understand why the line with glTexSubImage2D was incorrect as well, I've taken that out. It doesn't copy from system memory to the shader.
  11. Problem with multi-texturing [SOLVED]

    According to what I've just read, gl_TexCoord[i]; i = texture unit. It's not reflected above, but I currently have my vert and frag shader referencing gl_TexCoord[2], and in the vert shader I assign 'gl_TexCoord[2] = gl_MultiTexCoord2;'. Still not getting information from the GL_TEXTURE2 (data) texture in the output.
  12. Problem with multi-texturing [SOLVED]

    Actually, I changed that too already, and tried different variations; This is reflected above in my original post currently. VERT: void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; // also tried Coord 2 gl_Position = ftransform(); } FRAG: uniform sampler2D tex; uniform sampler2D atex; vec2 tloc, aloc; vec4 ca, sa; void main() { tloc = gl_TexCoord[0].xy; aloc = gl_TexCoord[1].xy; sa = texture2D( atex, aloc ); ca = texture2D( tex, tloc ); ca.r = sa.r; ca.g = sa.g; ca.b += 0.005; // loops through just to verify output ca = mod(ca, 1.0); gl_FragColor = ca; } I know that rendering works at least, because it does in fact cycle through values of BLUE as the shader is told to... just nothing from 'atex.'
  13. What if... you put an invisible sphere (not even a sphere, just a set of points around the camera at some set radius) around the camera and just did some collision detection on those key points? You'd only be checking for some 20 points or less, depends on what ever you arbitrarily decide.
  14. Problem with multi-texturing [SOLVED]

    First, I initialized the second FBO texture to GL_TEXTURE2, so I can't imagine I'd set 'glUniform1i' to 1 for the third texture I created. Also, I tried 1 anyway for arguments sake, still didn't work. Yes, I have changed it, I did take that portion out of the initialization regarding the color attachments. Here's the entire rendering loop: static GLint vLoc; fmresult = FMOD_Channel_GetWaveData(fmchannel, fmLBuf, SAMPLESIZE, 0); fmresult = FMOD_Channel_GetWaveData(fmchannel, fmRBuf, SAMPLESIZE, 1); // Omitted to save some space: // loop through TexAudio[SD][SD][4] filling it with data... from FMOD glBindTexture(GL_TEXTURE_2D, FBOTex[TexAudioData]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SD, SD, GL_RGBA, GL_UNSIGNED_BYTE, TexAudio); glUseProgram(p); glBindTexture(GL_TEXTURE_2D, FBOTex[TexRenderWrite]); glActiveTexture(GL_TEXTURE0); vLoc = glGetUniformLocation(p, "tex"); glUniform1i(vLoc, 0); // FBOTex[TexAudioData] is init as GL_TEXTURE2 glActiveTexture(GL_TEXTURE2); vLoc = glGetUniformLocation(p, "atex"); glUniform1i(vLoc, 2); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO); glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT); glViewport(0, 0, SD, SD); glDrawBuffer(AttchPoint[TexRenderRead]); glActiveTexture(GL_TEXTURE0 + TexRenderRead); glPushMatrix(); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, 0.0); glEnd(); glPopMatrix(); glPopAttrib(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); TexRenderRead = (TexRenderRead + 1)%2; TexRenderWrite = (TexRenderWrite + 1)%2; glUseProgram(0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glPushMatrix(); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f( 1.0, 1.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0, 0.0); glEnd(); glPopMatrix(); glutSwapBuffers(); Sleep(1);
  15. Problem with multi-texturing [SOLVED]

    OK, I spent more time re-reading everything... unless I'm retarded here, I think I did everything necessary for this to work. So where am I wrong here? I read every source I could find on textures, it seems like I've done everything I should... vLoc does return a location for all the sampler2d variables, and my textures obviously have been configured and set, and as my past post implies I did in fact set the texture to 'texture unit 2' via GL_TEXTURE2***
  • Advertisement