Hey all. I’ve been searching for hours on how to load an image and apply a texture to my particles with no resolve.
The following is my code which runs, but nothing appears on the screen. When I remove the texture code, the particles
do what they’re supposed to do, but they’re still simple GlPoints…
Any pointers will be appreciated.
private static int[] index;
private static int width;
private static int height;
/// <summary>
/// TEXTURE CODE
/// </summary>
[EnvironmentPermissionAttribute(SecurityAction.LinkDemand, Unrestricted = true)]//For codeanalyst
public static void Texture()
{
index = new int[1];
Gl.glGenTextures(1, index);
//LoadTexture(path);
}
[EnvironmentPermissionAttribute(SecurityAction.LinkDemand, Unrestricted = true)]//For codeanalyst
public static void LoadTexture(string path)
{
Bitmap image;
try
{
image = new Bitmap(path);
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
height = image.Height;
width = image.Width;
BitmapData bitmapdata = image.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
Gl.glEnable(Gl.GL_TEXTURE_2D); // Enable 2D Texture Mapping
// Gl.glDisable(Gl.GL_DEPTH_TEST); // Disable Depth Testing
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE); // Set Blending Mode
Gl.glEnable(Gl.GL_BLEND);
Gl.glEnable(Gl.GL_TEXTURE_GEN_S); //enable texture coordinate generation
Gl.glEnable(Gl.GL_TEXTURE_GEN_T);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, index[0]);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, image.Width, image.Height,
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, bitmapdata.Scan0);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP);
image.UnlockBits(bitmapdata);
image.Dispose();
}
catch (ArgumentException)
{
Environment.Exit(0);
}
}
public static void Activate()
{
Gl.glBindTexture(Gl.GL_TEXTURE_2D, index[0]);
}
public int GetWidth
{
get { return width; }
}
public int GetHeight
{
get { return height; }
}
/////END OF TEXTURE CODE
public static void DisplayRainSystem()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Texture();
LoadTexture("particle.bmp");
Activate();
float spost = 0.0f; // Starting Texture Coordinate Offset
float alphainc = 0.9f / 2; // Fade Speed For Alpha Blending
float alpha = 0.2f; // Starting Alpha Value
Gl.glPointSize(2.5f);
int RandomColour = R.Next(4) + 1;
if (RandomColour == 1) Gl.glColor3f(0.0f, 0.0f, 1.0f);
if (RandomColour == 2) Gl.glColor3f(0.0f, 0.1f, 1.0f);
if (RandomColour == 3) Gl.glColor3f(0.0f, 0.2f, 1.0f);
if (RandomColour == 4) Gl.glColor3f(0.0f, 0.5f, 1.0f);
if (RandomColour == 5) Gl.glColor3f(0.0f, 0.8f, 1.0f);
Gl.glBegin(Gl.GL_POINTS);
for (int i = 0; i <= RS.RainParticles.Count - 1; i++)
{
RainParticle RP = (RainParticle)RS.RainParticles[i];
Gl.glVertex2d(RP.xpos, RP.ypos);
}
Gl.glFlush();
Gl.glEnd();
}