Jump to content
  • Advertisement

keyofrassilon

Member
  • Content Count

    54
  • Joined

  • Last visited

Community Reputation

122 Neutral

About keyofrassilon

  • Rank
    Member
  1. Could someone that has access to the search capabilities of this forum conjure up all the relevant posts on the subject or point me in the right direction here.... I am currently using glRotate *shudders* to try and place an object (more a billboard) of a tree on the surface of a sphere...I tried using the normals that I calculated and those didnt give accurate results....or I was going about it all wrong....Currently I am using something along these lines... angleX1 = RADTODEG(double(j) * PI / (double(n)/2)); angleX2 = RADTODEG(double(j+1) * PI / (double(n)/2)); angleY1 = RADTODEG(double(i) * TWOPI / double(n))-90; angleY2 = RADTODEG(double(i+1) * TWOPI / double(n))-90; I split my array build up with two for loops i and j in the update and in the render output it obviously...The actual terrain, texturing and normals are all correct but the objects when placed offset one of the x, y or z planes start to lean dramatically the further away from each of these planes...I suppose glRotate is the problem and I should possibly build a vertex buffer of billboards instead of a single display list or static vertex buffer rotated each time? The actual class in its entirety is as listed below: #include "sphere.h" #include "stellartrader.h" #include "gl_graph.h" #include "perlin.h" char debugText[255]; float obj_billboard_norm[12][3] = {0.7071, 0.0000, 0.7071, 0.7071, 0.0000, 0.7071,0.7071, 0.0000, 0.7071, 0.7071, 0.0000, 0.7071,0.7071, 0.0000, 0.7071, 0.7071, 0.0000, 0.7071,-0.7071, 0.0000, 0.7071, -0.7071, 0.0000, 0.7071,-0.7071, 0.0000, 0.7071, -0.7071, 0.0000, 0.7071,-0.7071, 0.0000, 0.7071, -0.7071, 0.0000, 0.7071}; float obj_billboard_vert[12][3] = {-0.3536, 1.0000, 0.3536, -0.3536, 0.0000, 0.3536,0.3536, 1.0000, -0.3536, 0.3536, 0.0000, -0.3536,0.3536, 1.0000, -0.3536, -0.3536, 0.0000, 0.3536,-0.3536, 1.0000, -0.3536, -0.3536, 0.0000, -0.3536,0.3536, 1.0000, 0.3536, 0.3536, 0.0000, 0.3536,0.3536, 1.0000, 0.3536, -0.3536, 0.0000, -0.3536}; float obj_billboard_tex[12][3] = {0.9995, 0.9995, 0.9995, 0.0005,0.0005, 0.9995, 0.0005, 0.0005,0.0005, 0.9995, 0.9995, 0.0005,0.0000, 1.0000, 0.0000, 0.0000,1.0000, 1.0000, 1.0000, 0.0000,1.0000, 1.0000, 0.0000, 0.0000}; Sphere::Sphere(int n, int bwidth, int bheight) { normals.reserve(n * n * 4); texes.reserve(n * n * 4); verts.reserve(n * n * 4); colors.reserve(n * n * 4); objnormals.reserve(n * n * 4); objverts.reserve(n * n * 4); buffer.reserve((bwidth+1) * (bheight+1) * 4); l_buffer.reserve((bwidth+1) * (bheight+1) * 4); bufferWidth = bwidth; bufferHeight = bheight; maxSlices = n; numVerts = 0; vertCount = 0; hi = 0; lo = 10000; } Sphere::~Sphere() { } void Sphere::assignBuffer(unsigned char *b, unsigned char *l, int bwidth, int bheight, double bump) { for(int i=0;i<bufferWidth*bufferHeight*3;i++) { buffer = b; l_buffer = l; } bufferWidth = bwidth; bufferHeight = bheight; bumpHeight = bump; } Vec3d Sphere::CalculateNormals(Vec3d v1, Vec3d v2, Vec3d v3) { // Reduce each vert's normal to unit float length; float u[3], v[3]; Vec3d unit; // V2 - V3; u[0] = v2.x - v3.x; u[1] = v2.y - v3.y; u[2] = v2.z - v3.z; // V2 - V1; v[0] = v2.x - v1.x; v[1] = v2.y - v1.y; v[2] = v2.z - v1.z; unit.x = (u[1]*v[2] - u[2]*v[1]); unit.y = (u[2]*v[0] - u[0]*v[2]); unit.z = (u[0]*v[1] - u[1]*v[0]); length = (double)sqrt((unit.x*unit.x) + (unit.y*unit.y) + (unit.z*unit.z)); if (length == 0.0f) length = 1.0f; unit.x /= length; unit.y /= length; unit.z /= length; return unit; } void Sphere::setScale(double scale) { scaleSet = scale; } double Sphere::getHi() { return hi; } double Sphere::getLo() { return lo; } Vec2f Sphere::getSphereEyeCoord(Vec3d pos, Vec3d cam) { Vec2f coord; double x,y,z; coord.x = PI + (atan2(pos.z - cam.z,pos.x - cam.x)); x = pos.x - cam.x; y = pos.y - cam.y; z = pos.z - cam.z; coord.y = -(PI * 0.5f - atan2(sqrt(x*x+z*z),y)); return coord; } void Sphere::Update(Vec3d pos, Vec3d cam, double r,int n, bool useClip, bool useArea, bool useHeight) { int i,j,index = 0; double theta1,theta2,theta3; double angleX1, angleX2, angleY1, angleY2; double u, v, height; double hu, hv; double per; double part; float slice, restslice; int objindex = 0, objinc = 0; Vec3d e,p; Vec2d lalpha; // take horizontal camera - 90 degrees = center on closest vert; if(n > maxSlices) n = maxSlices; slices = n; radius = r; if (r < 0) r = -r; if (n < 0) n = -n; eyeSphere = getSphereEyeCoord(pos,cam); for (j=0;j<n/2;j++) { // rotate X for objects if(useArea) part = FABS((j / (n/2)) - 0.5) * 0.1; else part = 0.1; theta1 = double(j) * TWOPI / double(n) - PIDIV2; // vertical shift theta2 = (double(j) + 1) * TWOPI / double(n) - PIDIV2; slice = CLAMP(FABS(eyeSphere.y) * 0.25f * part * 10,0.1,1); if(theta1 > eyeSphere.y - PI * part && theta1 < eyeSphere.y + PI * part || n < 64 || !useArea && !useClip) { for (i=0;i<n;i++) { // rotate Y for objects theta3 = double(i) * TWOPI / double(n); // horizontal shift angleX1 = RADTODEG(double(j) * PI / (double(n)/2)); angleX2 = RADTODEG(double(j+1) * PI / (double(n)/2)); angleY1 = RADTODEG(double(i) * TWOPI / double(n))-90; angleY2 = RADTODEG(double(i+1) * TWOPI / double(n))-90; restslice = TWOPI - (TWOPI - PIDIV2 * slice); if(theta3 > eyeSphere.x - PI * slice && theta3 < eyeSphere.x + PI * slice || eyeSphere.x > TWOPI - PI * slice && theta3 > eyeSphere.x - PI * slice || eyeSphere.x > TWOPI - PI * slice && theta3 < restslice || eyeSphere.x < PI * slice && theta3 < eyeSphere.x + PI * slice || eyeSphere.x < PI * slice && theta3 > TWOPI - restslice || slice > 0.25f || n < 64 || !useArea) { u = (double(i)+0.08)/(double)n; v = 2*(double(j)+1.08)/(double)n; hu = i/(double)n * bufferWidth; hv = 2*(double(j)+1)/(double)n * bufferHeight; per = ((PerlinNoise2D(u * n,v * n,1,1,1.5)+1)/2); if(per > hi) hi = per; if(per < lo) lo = per; if(useHeight) { height = double(buffer[(hv * 3) * bufferWidth + hu * 3]) / 255 * bumpHeight; height = height * 2 - height; height = height * per; } else height = 0; e.x = cos(theta2) * cos(theta3); e.y = sin(theta2); e.z = cos(theta2) * sin(theta3); p.x = (r + height) * e.x; p.y = (r + height) * e.y; p.z = (r + height) * e.z; colors[index] = float(l_buffer[(hv * 3) * bufferWidth + hu * 3]) / 255.0f * per * 1.25; normals[index] = e; texes[index] = Vec2f(u,v); verts[index] = p; index++; objnormals[objindex] = Vec3d(angleX2,0,angleY1); objverts[objindex] = verts[index]; objindex++; u = (double(i)+0.08)/(double)n; v = 2*(double(j)+0.08)/(double)n; hu = i/(double)n * bufferWidth-0; hv = 2*(double(j)-0)/(double)n * bufferHeight; if(hv < 0) hv = 0; per = ((PerlinNoise2D(u * n,v * n,1,1,1.5)+1)/2); if(per > hi) hi = per; if(per < lo) lo = per; if(useHeight) { height = double(buffer[(hv * 3) * bufferWidth + hu * 3]) / 255 * bumpHeight; height = height * 2 - height; height = height * per; } else height = 0; e.x = cos(theta1) * cos(theta3); e.y = sin(theta1); e.z = cos(theta1) * sin(theta3); p.x = (r + height) * e.x; p.y = (r + height) * e.y; p.z = (r + height) * e.z; colors[index] = float(l_buffer[(hv * 3) * bufferWidth + hu * 3]) / 255.0f * per * 1.25; normals[index] = e; texes[index] = Vec2f(u,v); verts[index] = p; index++; theta3 = (double(i)+1) * TWOPI / double(n); u = (double(i)+1.08)/(double)n; v = 2*(double(j)+0.08)/(double)n; hu = (i+1)/(double)n * bufferWidth-0; hv = 2*(double(j)-0)/(double)n * bufferHeight; if(hv < 0) hv = 0; per = ((PerlinNoise2D(u * n,v * n,1,1,1.5)+1)/2); if(per > hi) hi = per; if(per < lo) lo = per; if(useHeight) { height = double(buffer[(hv * 3) * bufferWidth + hu * 3]) / 255 * bumpHeight; height = height * 2 - height; height = height * per; } else height = 0; e.x = cos(theta1) * cos(theta3); e.y = sin(theta1); e.z = cos(theta1) * sin(theta3); p.x = (r + height) * e.x; p.y = (r + height) * e.y; p.z = (r + height) * e.z; colors[index] = float(l_buffer[(hv * 3) * bufferWidth + hu * 3]) / 255.0f * per * 1.25; normals[index] = e; texes[index] = Vec2f(u,v); verts[index] = p; index++; objnormals[objindex] = Vec3d(angleX1,0,angleY2); objverts[objindex] = verts[index]; objindex++; u = (double(i)+1.08)/(double)n; v = 2*(double(j)+1.08)/(double)n; hu = (i+1)/(double)n * bufferWidth-0; hv = 2*(double(j)+1)/(double)n * bufferHeight; per = ((PerlinNoise2D(u * n,v * n,1,1,1.5)+1)/2); if(per > hi) hi = per; if(per < lo) lo = per; if(useHeight) { height = double(buffer[(hv * 3) * bufferWidth + hu * 3]) / 255 * bumpHeight; height = height * 2 - height; height = height * per; } else height = 0; e.x = cos(theta2) * cos(theta3); e.y = sin(theta2); e.z = cos(theta2) * sin(theta3); p.x = (r + height) * e.x; p.y = (r + height) * e.y; p.z = (r + height) * e.z; colors[index] = float(l_buffer[(hv * 3) * bufferWidth + hu * 3]) / 255.0f * per * 1.25; normals[index] = e; texes[index] = Vec2f(u,v); verts[index] = p; index++; } } } } numVerts = index; numObjects = objindex; } int Sphere::getCount() { return vertCount; } int Sphere::getVert() { return numVerts; } double Sphere::getClosestVecDistance(double scale, Vec3d cam) { return fabs(objverts[closestVec].distanceTo(cam)) - scale; } Vec3d Sphere::getClosestVecNormal() { return objnormals[closestVec]; } void Sphere::setBump(double scale, double bump) { bumpHeight = bump / scale; } void Sphere::setLightPos(Vec3d light) { lightPos = light; } void Sphere::Draw(double scale, int lod, Vec3d pos, Vec3d cam, bool useClip, bool useArea, bool useHeight, bool useMulti, float alpha) { double dist = 0, closest = 1e20, farthest = 0; double cdist = fabs(pos.distanceTo(cam)); double area = cdist / scale * (1 - (0.9 / scale)); double distCenter = fabs(cdist - radius); double clip = cdist / scale * (1 - (0.025 / scale)); Vec3d p; Vec2f eye = getSphereEyeCoord(pos,cam); if(eye.distanceTo(eyeSphere) > PI * 0.005f && useArea || eye.distanceTo(eyeSphere) > PI * 0.005f && useClip) Update(pos,cam,1,lod,useClip, useArea,useHeight); closestVec = 0; farthestVec = 0; glPushMatrix(); glTranslated(pos.x, pos.y, pos.z); glEnable(GL_NORMALIZE); glScaled(scale,scale,scale); glBegin(GL_QUADS); vertCount = 0; if(numVerts > 0) { for (int i=0;i<numVerts;i+=4) { p = pos + verts; dist = fabs(p.distanceTo(cam)) / scale; if(dist < closest) { closest = dist; closestVec = i; } if(dist > farthest) { farthest = dist; farthestVec = i; } if(useArea && dist < area || useClip && dist < clip || slices < 160) { if(useArea) glColor4f(colors,colors,colors,alpha); glNormal3dv(&normals.x); if(useMulti == true) { glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texes.x, texes.y); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texes.x, texes.y); } else glTexCoord2fv(&texes.x); glVertex3dv(&verts.x); if(useArea) glColor4f(colors[i+1],colors[i+1],colors[i+1],alpha); glNormal3dv(&normals[i+1].x); if(useMulti == true) { glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texes[i+1].x, texes[i+1].y); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texes[i+1].x, texes[i+1].y); } else glTexCoord2fv(&texes[i+1].x); glVertex3dv(&verts[i+1].x); if(useArea) glColor4f(colors[i+2],colors[i+2],colors[i+2],alpha); glNormal3dv(&normals[i+2].x); if(useMulti == true) { glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texes[i+2].x, texes[i+2].y); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texes[i+2].x, texes[i+2].y); } else glTexCoord2fv(&texes[i+2].x); glVertex3dv(&verts[i+2].x); if(useArea) glColor4f(colors[i+3],colors[i+3],colors[i+3],alpha); glNormal3dv(&normals[i+3].x); if(useMulti == true) { glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texes[i+3].x, texes[i+3].y); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texes[i+3].x, texes[i+3].y); } else glTexCoord2fv(&texes[i+3].x); glVertex3dv(&verts[i+3].x); vertCount+=4; } } p = pos + verts[farthestVec]; dist = fabs(p.distanceTo(cam)); } glEnd(); glDisable(GL_NORMALIZE); glPopMatrix(); } void Sphere::DrawObjects(double scale, Vec3d pos, Vec3d cam, float alpha) { double dist = 0, closest = 1e20, farthest = 0; double cdist = fabs(pos.distanceTo(cam)); double area = cdist * 0.05; double distCenter; double clip = cdist / scale * (1 - (0.025 / scale)); Vec3d p, n, v; glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); if(numObjects > 0) { for (int i=0;i<numObjects;i++) { p = pos + objverts * scale; dist = fabs(p.distanceTo(cam)); distCenter = fabs(p.distanceTo(pos)); if(dist < closest) { closest = dist; closestVec = i; } n.x = objnormals.x; n.y = objnormals.y; n.z = objnormals.z; v.x = pos.x + objverts.x * scale; v.y = pos.y + objverts.y * scale; v.z = pos.z + objverts.z * scale; if(dist < area && distCenter > bumpHeight * scale * 150.25 && distCenter < bumpHeight * scale * 150.35) { glColor4f(1,1,1,alpha); drawTree(0.1,v,n); } } } glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); } void Sphere::drawTree(float radius, Vec3d pos, Vec3d rot) { glPushMatrix(); glTranslated(pos.x,pos.y,pos.z); glRotated(rot.x, 1.0, 0.0, 0.0); glRotated(rot.y, 0.0, 1.0, 0.0); glRotated(rot.z, 0.0, 0.0, 1.0); glEnable(GL_NORMALIZE); glScaled(radius, radius, radius); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer (2, GL_FLOAT, 0, obj_billboard_tex); glNormalPointer (GL_FLOAT, 0, obj_billboard_norm); glVertexPointer (3, GL_FLOAT, 0, obj_billboard_vert); glDrawArrays(GL_TRIANGLES, 0, 12); glDisableClientState (GL_VERTEX_ARRAY); glDisableClientState (GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_NORMALIZE); glPopMatrix(); } I prefer not to have to use something too complicated and would lean more to a simpler approach if at all possible...
  2. keyofrassilon

    Understanding masking...

    I give up.... Can someone delete my account please?
  3. keyofrassilon

    Understanding masking...

    Well in basic terms I want to render a planets atmosphere using a gradient ring as a mask and a lit sphere as the color map...A gradient ring is a circle thats very blurred and a lit sphere is a 3d object with light on one side...When I mean color map I mean that I want the mask to look like the lit sphere but inside the mask..same color...same side lit...The rest is cut away and tossed into the peverbial trash can! I want to combine this: With this: to get whats around the main body of saturn...and its not the rings...
  4. keyofrassilon

    Understanding masking...

    Well after consistant tries in various combinations I have come to the conclusion this is not possible...so if anyone else has had a similar problem...there is your answer...It cannot be done unless you use two textures in ortho mode...
  5. keyofrassilon

    Understanding masking...

    AN alternate explanation of what I am trying to do in a sense is I want to use an object as an alpha map and another object as the color map...Consider it a 3d RGBA....Like in a 32 bit Targa image anything in white is drawn to the buffer and anything black is not and anything grey is transparent...
  6. I need to know if it is possible to blend a mask texture with an object... If I use a gradient sphere as a mask and apply a lit sphere on top should I have what appears to be a lit gradient? example: enable texturing disable lighting Bind mask glDisable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBlendFunc(GL_DST_COLOR, GL_ZERO); Draw Mask disable texturing enable lighting glDisable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); Draw untextured lit sphere If not it could explain why I get a solid sphere instead of the mask lit by the blending of the sphere with the mask... Basically I want only the mask to show with the lighting of the sphere...No portion of the sphere should lie outside of the mask...
  7. keyofrassilon

    Billboards but not particles

    Ahh I did after I posted that reply....I must have looked at that tutorial several times before and always concluded it was doing the same thing as what I had...except it doesnt pull from the current modelview matrix.... I got it to do what I wanted using the spherical code in that tut...Originally I intended to capture the surrounding space into buffers and render them as a skybox for the planet's surface...The old billboarding method I used moved around too much to take seamless shots of the surrounding space...The new code fixed just that...Thanks! If anyone is interested this is what I did to snapshot the surrounding space into buffers...Its ugly but it works... void Engine::captureTerrainBox() { float view = 90.0f; float clip_min = 0.1f; float clip_max = bounds * 10; glFinish(); //make sure everything has been sent glutSwapBuffers(); //swap the front and back buffers to display the image screenX = TERRAIN_BACK; screenY = TERRAIN_BACK; captureSkybox = true; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 0; facing2 = 180; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 360; facing2 = 180; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glReadBuffer(GL_BACK); glReadPixels(0,0,screenX,screenY,GL_RGB,GL_UNSIGNED_BYTE,terrain_back[0]); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 270; facing2 = 180; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glReadBuffer(GL_BACK); glReadPixels(0,0,screenX,screenY,GL_RGB,GL_UNSIGNED_BYTE,terrain_back[1]); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 180; facing2 = 180; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glReadBuffer(GL_BACK); glReadPixels(0,0,screenX,screenY,GL_RGB,GL_UNSIGNED_BYTE,terrain_back[2]); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 90; facing2 = 180; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glReadBuffer(GL_BACK); glReadPixels(0,0,screenX,screenY,GL_RGB,GL_UNSIGNED_BYTE,terrain_back[3]); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 360; facing2 = 269.999999; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glReadBuffer(GL_BACK); glReadPixels(0,0,screenX,screenY,GL_RGB,GL_UNSIGNED_BYTE,terrain_back[4]); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(view, (GLfloat)screenX / (GLfloat) screenY, clip_min, clip_max); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); facing = 360; facing2 = 90.000001; camera.updateCamera(); sys.drawSolarSystem(); glFinish(); //make sure everything has been sent glReadBuffer(GL_BACK); glReadPixels(0,0,screenX,screenY,GL_RGB,GL_UNSIGNED_BYTE,terrain_back[5]); glDeleteTextures(1,&terrain_backID[0]); glDeleteTextures(1,&terrain_backID[1]); glDeleteTextures(1,&terrain_backID[2]); glDeleteTextures(1,&terrain_backID[3]); glDeleteTextures(1,&terrain_backID[4]); glDeleteTextures(1,&terrain_backID[5]); glGenTextures(1, &terrain_backID[0]); glBindTexture(GL_TEXTURE_2D, terrain_backID[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenX, screenY, 0, GL_RGB, GL_UNSIGNED_BYTE, terrain_back[0]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &terrain_backID[1]); glBindTexture(GL_TEXTURE_2D, terrain_backID[1]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenX, screenY, 0, GL_RGB, GL_UNSIGNED_BYTE, terrain_back[1]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &terrain_backID[2]); glBindTexture(GL_TEXTURE_2D, terrain_backID[2]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenX, screenY, 0, GL_RGB, GL_UNSIGNED_BYTE, terrain_back[2]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &terrain_backID[3]); glBindTexture(GL_TEXTURE_2D, terrain_backID[3]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenX, screenY, 0, GL_RGB, GL_UNSIGNED_BYTE, terrain_back[3]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &terrain_backID[4]); glBindTexture(GL_TEXTURE_2D, terrain_backID[4]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenX, screenY, 0, GL_RGB, GL_UNSIGNED_BYTE, terrain_back[4]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glGenTextures(1, &terrain_backID[5]); glBindTexture(GL_TEXTURE_2D, terrain_backID[5]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenX, screenY, 0, GL_RGB, GL_UNSIGNED_BYTE, terrain_back[5]); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtered glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); screenX = SCREEN_X; screenY = SCREEN_Y; captureSkybox = false; glReadBuffer(GL_FRONT); glViewport(0, 0, (GLsizei)screenX, (GLsizei)screenY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(PERSPECTIVE, (GLfloat)screenX / (GLfloat) screenY, 10.0f, bounds); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glClearColor(0.0, 0.0, 0.0, 0.0); glDepthRange(0.0, 1.0); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, white_mat); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glFinish(); //make sure everything has been sent glutSwapBuffers(); //swap the front and back buffers to display the image } What I really need is a way to render GL directly into a buffer bypassing the default back color buffer which could allow me to create any size image...Right now Im limited to the maximum Y size of the screen...Anything less than 1024 x 1024 for this sort of texture is very pixelated...
  8. keyofrassilon

    Billboards but not particles

    I mean facing based on position not camera orientation...
  9. I am currently developing a space sim and require the use of billboards for nebula, sunflares and galaxies....I currently have a billboarding system set up that unfortunately is based on the view of the camera and not its position...What I need is something similar to glPointParameterfARB point sprite extention that will allow me to have points of any size or regular billboarding that is not affected by the view of the camera. I need the billboards to face the camera yes but I do not want them to move when I face a different direction unless I move from the current position...Im not sure what type of billboarding this will be but if anyone would be gracious enough to provide some links to tutorials with code examples it would be much appreciated...Im not the strongest with math so its no use speaking greek to me ;)
  10. How would I draw any object weither it be a poly or a point beyond the far clipping plane without flickering? Ive tried disabling z-buffer with glDisable(GL_DEPTH_TEST) but it will draw the object in front of other objects which I do not want...I have also tried the various glDepthFunc enums to no avail and even tried glDisable(GL_CLIP_PLANE0) but I figure I am not using it correctly...Initially I want to disable gluPerspective effects for a short period so I do not get z-fighting in the distance...Due mainly because I am trying to draw objects such as stars at distances of trillions of GL units away along with objects up close that are relatively small such as planets...
  11. keyofrassilon

    classes and arrays

    Well I would set up a public bool and assign it true or false instead of trying to pass it into the constructor. I dont think you can set a constructor array like that. from C2DBitmap *bitmap = new C2DBitmap[3]( true, false ); to C2DBitmap *bitmap = new C2DBitmap[3]; bitmap[0]->myFlag = true; bitmap[0]->myFlag2 = false; bitmap[1]->myFlag = true; bitmap[1]->myFlag2 = false; bitmap[2]->myFlag = true; bitmap[2]->myFlag2 = false; or use a for loop depending.
  12. keyofrassilon

    WAV loop glitch

    I have this snippet of code which I followed a tutorial on to get working...however I am unable to understand why the writer of the tutorial failed to realise there is a slight pause when looping a WAV file using the code...and I am wondering if anyone else could possibly see if there is a way to stop this in the current code I have provided or post a possible better tutorial on loading and playing wav files... WAVEFORMATEX wfex; HWAVEOUT hwo; char *lpfile; int file_size; #define OFFSET_FORMATTAG 20 #define OFFSET_CHANNELS 22 #define OFFSET_SAMPLESPERSEC 24 #define OFFSET_AVGBYTESPERSEC 28 #define OFFSET_BLOCKALIGN 32 #define OFFSET_BITSPERSAMPLE 34 #define OFFSET_WAVEDATA 44 #define HEADER_SIZE OFFSET_WAVEDATA bool LoadWave(LPSTR szFileName) { FILE *f; // Handler to load the file into memory // Open and read the wave file f = fopen(szFileName, "rb"); if(!f) // Error, file not found. return true; // Determine the file size fseek(f, 0, SEEK_END); file_size = ftell(f); // Rewind the pointer to the begginning so we can read it fseek(f, 0, SEEK_SET); // Allocate enough memory to store the entire file lpfile = new char [file_size]; // 'Copy' the file to memory fread(lpfile, 1, file_size, f); // Close the file, we won't need it anymore fclose(f); wfex.wFormatTag = *((WORD* )(lpfile + OFFSET_FORMATTAG )); wfex.nChannels = *((WORD* )(lpfile + OFFSET_CHANNELS )); wfex.nSamplesPerSec = *((DWORD*)(lpfile + OFFSET_SAMPLESPERSEC )); wfex.nAvgBytesPerSec = *((DWORD*)(lpfile + OFFSET_AVGBYTESPERSEC)); wfex.nBlockAlign = *((WORD* )(lpfile + OFFSET_BLOCKALIGN )); wfex.wBitsPerSample = *((WORD* )(lpfile + OFFSET_BITSPERSAMPLE )); return false; } void CALLBACK WaveOutProc( HWAVEOUT hwo, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { switch(uMsg) { case WOM_OPEN: break; case WOM_DONE: { WAVEHDR *whdr = (WAVEHDR*)dwParam1; // Only to keep the clarity of the code if(whdr->dwUser) waveOutWrite(hwo, whdr, sizeof(WAVEHDR)); else { waveOutUnprepareHeader(hwo, whdr, sizeof(WAVEHDR)); delete whdr; } } break; case WOM_CLOSE: break; } } WAVEHDR* PlayWave(bool loop) { WAVEHDR *whdr = new WAVEHDR; ZeroMemory((void*)whdr, sizeof(WAVEHDR)); whdr->lpData = lpfile+HEADER_SIZE; whdr->dwBufferLength = file_size-HEADER_SIZE; whdr->dwUser = (DWORD)loop; // Find a waveOut device and open it for(UINT devid = 0; devid < waveOutGetNumDevs(); devid++) { if(devid == waveOutGetNumDevs()) // Error, no free devices found return NULL; if(waveOutOpen(&hwo, WAVE_MAPPER, &wfex, (DWORD)WaveOutProc, 0, CALLBACK_FUNCTION) == MMSYSERR_NOERROR) // Usable device found, stop searching break; } if(waveOutPrepareHeader(hwo, whdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) return NULL; if(waveOutWrite(hwo, whdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) return NULL; // Return the pointer to the WAVEHDR we used here return whdr; } void StopWave(WAVEHDR *whdr) { if(whdr) whdr->dwUser = (DWORD)false; } void CloseWave() { waveOutClose(hwo); delete [] lpfile; } Thanks!
  13. keyofrassilon

    3ds mesh seam?

    Well Ive been reading about this problem elsewhere and noticed this blurb from TurboSquid... Quote: If you export to pure .3DS format withouth "Preserve MAX mapping" checked, all texture vertices at the poles (as many as there are faces meeting at the pole) will be reduced to just one! This will cause severe distortion at the poles. If you export using the "Preserve..." option, the pole vertex will be multiplied to make place for the multiple texture vertices. The mapping will be better, but the smoothing groups will no longer work at the poles and at the seam along the back meridian and you will get some facetted faces.. It seems its a problem with the 3ds file format...so I am probably going to have to scrap the entire code and use another format...The thing is what format is small like 3ds AND I can export using 3d studio max 6?
  14. keyofrassilon

    3ds mesh seam?

    Heres a screen of the problem: seam pic
  15. keyofrassilon

    OpenGL 3ds mesh seam?

    I have built a 3ds loader that converts the data into vertex arrays and draws them using the glDrawElements format in OpenGL...Now when I display the mesh textured or non textured I notice this 'seam'. Now using 3ds files in other programs I have noticed this same seam which worsens when you apply a displacement map so this seems to be exclusive to the 3ds file format. Its like one of those rubber toys with the seam from the mold appearing. Its rather annoying to say the least... What would cause this? And if anyone else has had this problem how did you go about fixing it?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!