|
编译没问题,运行到 glActiveTexture(GL_TEXTURE0); 时出现0xC0000005: Access Violation,注掉这句就没问题,新手,请高人指教,谢了!
//#include "glos.h"
#include <windows.h>
#include <stdio.h> // Header File For Standard Input/Output
/*
#include <GL/gl.h>
#include <GL/glu.h>
*/
#include <GL/glew.h>
#include <GL/glut.h>
void myinit(void);
#define ImageWidth 256
#define ImageHeight 256
GLubyte Image[ImageWidth][ImageHeight][3];
GLuint texturein[2];
void makeImage(void)
{
int i, j, r,g,b;
for (i = 0; i < ImageWidth; i++)
{
for (j = 0; j < ImageHeight; j++)
{
r=(i*j)%255;
g=(4*i)%255;
b=(4*j)%255;
Image[j][0] = (GLubyte) r;
Image[j][1] = (GLubyte) g;
Image[j][2] = (GLubyte) b;
}
}
}
/* 初始化 alpha 融合的参数 */
void myinit(void)
{
//glEnable (GL_BLEND);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
makeImage();
glDisable(GL_BLEND);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glShadeModel (GL_FLAT);
glGenTextures(2, &texturein[0]);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, 3, ImageWidth, ImageHeight, 0,GL_RGB, GL_UNSIGNED_BYTE, Image);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
static void redraw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.5, 0.0);
glTexCoord2f(0.0, 1.0); glVertex2f(0.5, 0.5);
glTexCoord2f(1.0, 1.0); glVertex2f(0.0, 0.5);
glTexCoord2f(1.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(0.0, 0.0); glVertex2f(0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex2f(0.5, 1.0);
glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.5);
glEnd();
glFlush();
}
static void resize(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D (0.0, 1.0, 0.0, 1.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D (0.0, 1.0*(GLfloat)w/(GLfloat)h, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitWindowSize(512, 512);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
(void) glutCreateWindow("STEVE TEST");
glutDisplayFunc(redraw);
glutReshapeFunc(resize);
myinit();
glutMainLoop();
}
|
|