//! TEXTURE CUBE e void GenerateTextures() { GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glGenTextures(6, Textures); GL.glGenTextures(1, TextureGround); string[] imgGroundName = { "Sand.bmp" }; string[] imagesName = { "front.bmp", "back.bmp", "left.bmp", "right.bmp","top.bmp","bottom.bmp", }; for (int i = 0; i < 6; i++) { Bitmap image = new Bitmap(imagesName[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[i]); //2D for XYZ GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); image.UnlockBits(bitmapdata); image.Dispose(); } { Bitmap imageG = new Bitmap(imgGroundName[0]); imageG.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdataG; Rectangle rect = new Rectangle(0, 0, imageG.Width, imageG.Height); bitmapdataG = imageG.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, TextureGround[0]); //2D for XYZ GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, imageG.Width, imageG.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdataG.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); imageG.UnlockBits(bitmapdataG); imageG.Dispose(); } }
void drawFloorTextured() { GL.glEnable(GL.GL_TEXTURE_2D); GL.glDisable(GL.GL_BLEND); GL.glColor3d(1, 1, 1); GL.glDisable(GL.GL_LIGHTING); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[5]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(0, 1, 0); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-200, -0.01f, 200); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(200, -0.01f, 200); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(200, -0.01f, -200); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-200, -0.01f, -200); GL.glEnd(); GL.glDisable(GL.GL_TEXTURE_2D); GL.glEnable(GL.GL_BLEND); GL.glEnable(GL.GL_LIGHTING); }
private void DrawBackground() { GL.glDisable(GL.GL_LIGHTING); GL.glEnable(GL.GL_TEXTURE_2D); GL.glColor4f(1.0f, 1.0f, 1.0f, 0.5f); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[4]); float cor = GlobalProperties.seaSize / 2; GLUquadric obj = GLU.gluNewQuadric(); GLU.gluQuadricTexture(obj, 4); GLU.gluCylinder(obj, cor, cor, cor, 32, 32); GLU.gluDeleteQuadric(obj); GL.glDisable(GL.GL_TEXTURE_2D); GL.glEnable(GL.GL_LIGHTING); }
public static uint[] Textures = new uint[9]; // texture void GenerateTextures() { GL.glGenTextures(9, Textures); string[] imagesName = { "world.bmp", "side.bmp", "top.bmp", "back.bmp", "ontop.bmp", "front.bmp", "sky.bmp", "fire.bmp", "target.bmp" }; for (int i = 0; i < 9; i++) { Bitmap image = new Bitmap(imagesName[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[i]); //2D for XYZ //The level-of-detail number. Level 0 is the base image level //The number of color components in the texture. //Must be 1, 2, 3, or 4, or one of the following // symbolic constants: // GL_ALPHA, GL_ALPHA4, // GL_ALPHA8, GL_ALPHA12, GL_ALPHA16, GL_LUMINANCE, GL_LUMINANCE4, // GL_LUMINANCE8, GL_LUMINANCE12, GL_LUMINANCE16, GL_LUMINANCE_ALPHA, // GL_LUMINANCE4_ALPHA4, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, // GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12, GL_LUMINANCE16_ALPHA16, // GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, GL_INTENSITY12, // GL_INTENSITY16, GL_R3_G3_B2, GL_RGB, GL_RGB4, GL_RGB5, GL_RGB8, // GL_RGB10, GL_RGB12, GL_RGB16, GL_RGBA, GL_RGBA2, GL_RGBA4, GL_RGB5_A1, // GL_RGBA8, GL_RGB10_A2, GL_RGBA12, or GL_RGBA16. GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, //The width of the border. Must be either 0 or 1. //The format of the pixel data //The data type of the pixel data //A pointer to the image data in memory 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); image.UnlockBits(bitmapdata); image.Dispose(); } }
void GenerateTextures() { GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glGenTextures(9, Textures); string[] imagesName = { "kalahk.jpg", "divingsuit.jpg", "Wall_Texture_1_by_Insan_Stock.jpg", "stock-photo-old-brick-wall-texture-66007105.jpg", "stock-photo-old-brick-wall-texture-73022833.jpg", "Concrete_Basement_Wall_Texture_by_FantasyStock.jpg", "top.bmp", "stock-photo-185015-floor-texture-6.jpg", "Scared_face.jpg" }; GL.glGenTextures(6, Textures); //monster = new Milkshape.Character("kalahk.ms3d"); //diver = new Milkshape.Character("diver.ms3d"); //skip on the first two images for (int i = 2; i < 9; i++) { Bitmap image = new Bitmap(imagesName[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[i]); //2D for XYZ GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); if (i == 5) { GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_SPHERE_MAP); } else { GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); } image.UnlockBits(bitmapdata); image.Dispose(); } }
private void DrawWindow() { float windowRadius = GlobalProperties.windowRadius, wondowHeight = GlobalProperties.windowHeight; GL.glEnable(GL.GL_TEXTURE_2D); GL.glColor3f(1.0f, 1.0f, 1.0f); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[5]); GLUquadric obj = GLU.gluNewQuadric(); GLU.gluQuadricTexture(obj, 5); GLU.gluCylinder(obj, windowRadius, windowRadius, wondowHeight, 32, 32); GL.glTranslatef(0.0f, 0.0f, wondowHeight); GLU.gluCylinder(obj, windowRadius, 0, wondowHeight * 2 / 3, 32, 32); GL.glTranslatef(0.0f, 0.0f, -wondowHeight / 2); GLU.gluDeleteQuadric(obj); GL.glDisable(GL.GL_TEXTURE_2D); }
void InitTexture(string imageBMPfile) { GL.glEnable(GL.GL_TEXTURE_2D); Bitmap image = new Bitmap(imageBMPfile); image.RotateFlip(RotateFlipType.RotateNoneFlipY); System.Drawing.Imaging.BitmapData bitmapdata; Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); bitmapdata = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); GL.glGenTextures(1, texture); GL.glBindTexture(GL.GL_TEXTURE_2D, texture[0]); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapdata.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); image.UnlockBits(bitmapdata); image.Dispose(); }
void DrawSky(float skysize) { float mid = skysize; GL.glEnable(GL.GL_TEXTURE_2D); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[6]); GL.glDisable(GL.GL_LIGHTING); GL.glTranslatef(0, 0, -mid); GL.glRotatef(90, 0, 0, 1); GL.glRotatef(zavit, 1, 0, 0); GLU.gluQuadricTexture(obj, 1); GLU.gluSphere(obj, skysize * 1.5f, 50, 50); GL.glRotatef(-zavit, 1, 0, 0); GL.glRotatef(-90, 0, 0, 1); GL.glTranslatef(0, 0, mid); GL.glEnable(GL.GL_LIGHTING); GL.glDisable(GL.GL_TEXTURE_2D); zavit += 0.02f; }
void drawground() { { GL.glBindTexture(GL.GL_TEXTURE_2D, TextureGround[0]); GL.glNormal3f(0.0f, -1.0f, 0.0f); GL.glBegin(GL.GL_QUADS); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3d(-20, -20, ground[0, 2] - 0.05); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3d(-20, 20, ground[0, 2] - 0.05); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3d(20, 20, ground[0, 2] - 0.05); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3d(20, -20, ground[0, 2] - 0.05); GL.glColor3f(0, 0, 0); GL.glEnd(); } }
void InitTexture() { GL.glEnable(GL.GL_TEXTURE_2D); m_textureList = new uint[4]; // storage for texture string[] bmpFilesPath = new string[m_textureList.Length]; bmpFilesPath[0] = "../../Resources/noon.bmp"; bmpFilesPath[1] = "../../Resources/gimel.bmp"; bmpFilesPath[2] = "../../Resources/hei.bmp"; bmpFilesPath[3] = "../../Resources/pei.bmp"; GL.glGenTextures(m_textureList.Length, m_textureList); for (int i = 0; i < m_textureList.Length; i++) { Bitmap image = new Bitmap(bmpFilesPath[i]); image.RotateFlip(RotateFlipType.RotateNoneFlipY); //Y axis in Windows is directed downwards, while in OpenGL-upwards if (i == 0 || i == 3) // instead of drawing the texture in different way in drawSquareSurface, we flip here the texture { image.RotateFlip(RotateFlipType.RotateNoneFlipX); } Rectangle rect = new Rectangle(0, 0, image.Width, image.Height); BitmapData bitmapData = image.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); GL.glBindTexture(GL.GL_TEXTURE_2D, m_textureList[i]); // VN-in order to use System.Drawing.Imaging.BitmapData Scan0 I've added overloaded version to // OpenGL.cs // [DllImport(GL_DLL, EntryPoint = "glTexImage2D")] // public static extern void glTexImage2D(uint target, int level, int internalformat, int width, int height, int border, uint format, uint type, IntPtr pixels); GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, (int)GL.GL_RGB8, image.Width, image.Height, 0, GL.GL_BGR_EXT, GL.GL_UNSIGNED_byte, bitmapData.Scan0); GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR); // Linear Filtering GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR); // Linear Filtering image.UnlockBits(bitmapData); image.Dispose(); } }
private void DrawDisk(double diskHeight, double diskRadius) { GL.glEnable(GL.GL_TEXTURE_2D); GL.glColor3f(1.0f, 1.0f, 1.0f); GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[3]); GL.glPushMatrix(); GLUquadric obj = GLU.gluNewQuadric(); GLU.gluQuadricTexture(obj, 3); GLU.gluDisk(obj, 0, diskRadius, 60, 20); GLU.gluCylinder(obj, diskRadius, diskRadius, diskHeight, 32, 32); GL.glTranslatef(0.0f, 0.0f, (float)diskHeight); GLU.gluDisk(obj, 0, diskRadius, 60, 20); GL.glPopMatrix(); // GL.glTranslatef(0.0f, 0.0f, -(float)diskHeight); GLU.gluDeleteQuadric(obj); GL.glDisable(GL.GL_TEXTURE_2D); }
public void Prepare() { radius = 0.18f; Robot_LIST = GL.glGenLists(7); ARM_LIST = Robot_LIST + 1; SHOULDER_LIST = Robot_LIST + 2; HAND_LIST = Robot_LIST + 3; BODY_LIST = Robot_LIST + 4; HEAD_LIST = Robot_LIST + 5; LEG_UP_LIST = Robot_LIST + 6; LEG_DOWN_LIST = Robot_LIST + 7; GL.glPushMatrix(); GL.glNewList(HEAD_LIST, GL.GL_COMPILE); GL.glTranslatef(0, 1, 0); //head GL.glPushMatrix(); GL.glTranslatef(0, 1, 0); GL.glRotatef(-90, 1, 0, 0); GL.glEnable(GL.GL_LIGHTING); GL.glBindTexture(GL.GL_TEXTURE_2D, this.headTexture); GL.glEnable(GL.GL_TEXTURE_2D); GLU.gluSphere(obj, radius * 3.5, 20, 20); GL.glDisable(GL.GL_TEXTURE_2D); GL.glRotatef(180, 1, 0, 0); GLU.gluCylinder(obj, 3.5 * radius, 3.5 * radius, radius * 2, 20, 20); GL.glTranslatef(0, 0, radius * 2); GLU.gluCylinder(obj, 3.5 * radius, 0.5, radius * 2, 20, 20); GL.glTranslatef(0, 0, radius * 2); GLU.gluCylinder(obj, 0.5, 0, radius * 2, 20, 20); GL.glPopMatrix(); GL.glEndList(); GL.glPopMatrix(); GL.glPushMatrix(); GL.glNewList(BODY_LIST, GL.GL_COMPILE); //ALL body //neck GL.glPushMatrix(); GL.glRotatef(90, 1, 0, 0); GL.glTranslatef(0, 0, -2.0f); GLU.gluCylinder(obj, 1.5 * radius, 1.5 * radius, bodyLength, 20, 20); GL.glPopMatrix(); ////body up GL.glRotatef(90, 1, 0, 0); GL.glTranslatef(0, 0, -1.2f); GLU.gluCylinder(obj, radius, 6 * radius, bodyLength / 4, 20, 20); GL.glTranslatef(0, 0, 1.2f); //body midle GL.glScalef(1.0f, -1.0f, 1.0f); GL.glTranslatef(0, 0, -(bodyLength / 4 + 0.2f)); GLU.gluCylinder(obj, 6 * radius, 3 * radius, bodyLength / 1.5f, 20, 20); GL.glTranslatef(0, 0, (bodyLength / 4 + 0.2f)); GL.glScalef(1.0f, 1.0f, 1.0f); //Tusik GLU.gluCylinder(obj, 3 * radius, 3 * radius, bodyLength / 1.5f, 20, 20); //body down GL.glTranslatef(0, 0, (bodyLength / 1.5f)); GLU.gluCylinder(obj, 3 * radius, radius, bodyLength / 3.5f, 10, 10); GL.glTranslatef(0, 0, -(bodyLength / 1.5f)); GL.glRotatef(-90, 1, 0, 0); GL.glEndList(); GL.glPopMatrix(); DrawDynamicHand(); GL.glPushMatrix(); GL.glNewList(LEG_UP_LIST, GL.GL_COMPILE); //leg_up GLU.gluCylinder(obj, 1.5f * radius, 1.5f * radius, legUpLength, 20, 20); GL.glTranslated(0, 0, legUpLength); GLU.gluSphere(obj, radius * 1.7f, 20, 20); GL.glEndList(); GL.glPopMatrix(); GL.glPushMatrix(); GL.glNewList(LEG_DOWN_LIST, GL.GL_COMPILE); //leg_down GLU.gluCylinder(obj, 1.5f * radius, 1.5f * radius, legDownLength, 20, 20); GL.glTranslated(0, 0, legDownLength); GLU.gluSphere(obj, 1.7f * radius, 20, 20); GL.glEndList(); GL.glPopMatrix(); }
public void DrawTexturedCube() { GL.glScaled(55, 55, 55); { // front GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[0]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(0.0f, 0.0f, 1.0f); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, 1.0f); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(1.0f, -1.0f, 1.0f); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(1.0f, 1.0f, 1.0f); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f, 1.0f, 1.0f); GL.glEnd(); // back GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[1]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(0.0f, 0.0f, -1.0f); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(1.0f, -1.0f, -1.0f); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f, 1.0f, -1.0f); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(1.0f, 1.0f, -1.0f); GL.glEnd(); // left GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[2]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(-1.0f, 0.0f, 0.0f); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, 1.0f); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f, 1.0f, 1.0f); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f, 1.0f, -1.0f); GL.glEnd(); // right GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[3]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(1.0f, 0.0f, 0.0f); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(1.0f, -1.0f, 1.0f); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(1.0f, -1.0f, -1.0f); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(1.0f, 1.0f, -1.0f); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(1.0f, 1.0f, 1.0f); GL.glEnd(); // top GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[4]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(0.0f, 1.0f, 0.0f); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, 1.0f, 1.0f); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(1.0f, 1.0f, 1.0f); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(1.0f, 1.0f, -1.0f); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f, 1.0f, -1.0f); GL.glEnd(); // bottom GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[5]); GL.glBegin(GL.GL_QUADS); GL.glNormal3f(0.0f, -1.0f, 0.0f); GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f); GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(1.0f, -1.0f, -1.0f); GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(1.0f, -1.0f, 1.0f); GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f, -1.0f, 1.0f); GL.glEnd(); } }