Dear Zengar,
Thanks for your quick reply. The problem is that I am implementing a color cube using opengl. I am using the code in the attached file, but it is too slow. I tought that the glDrawPixels function can be fater, but it is slower.
Please can you tell me is there any way that is faster than the one I am using.
Thanks in advance for your help.
#include <GL/glut.h>
#include <stdio.h>
void redraw();
void mouseClicked(int, int, int, int);
void mouseMoved(int,int);
void reshape(int, int);
float spinX = 0.0f;
float spinZ = 0.0f;
int mousePosX = 0;
int mousePosY = 0;
void main()
{
glutInitWindowSize(700, 700);
glutInitWindowPosition(50, 50);
glutCreateWindow("Test");
glutDisplayFunc(redraw);
glutReshapeFunc(reshape);
glutMouseFunc(mouseClicked);
glutMotionFunc(mouseMoved);
glutMainLoop();
}
void redraw()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT );
glPushMatrix();
glRotatef(spinZ, 1, 0, 0);
glRotatef(spinX, 0, 0, 1);
for (int r = 0; r < 255; r++)
{
for (int g = 0; g < 255; g++)
{
for (int b = 0; b < 255; b++)
{
//using glDrawPixels
//float color[3] = {(float)r / 255, (float)g / 255, (float)b / 255};
//glRasterPos3f(r - 127.5, g - 127.5, b - 127.5);
//glDrawPixels(1, 1, GL_RGB, GL_FLOAT, color);
//using glVertex3f
glColor3f((float)r / 255, (float)g / 255, (float)b / 255);
glBegin(GL_POINTS);
glVertex3f(r - 127.5, g - 127.5, b - 127.5);
glEnd();
}
}
}
glPopMatrix();
//glFlush();
glutSwapBuffers();
}
void mouseClicked(int button, int state, int xMouse, int yMouse)
{
if(state == GLUT_DOWN)
{
mousePosX = xMouse;
mousePosY = yMouse;
}
glutPostRedisplay();
}
void mouseMoved(int xMouse,int yMouse)
{
spinX += (float)(xMouse - mousePosX) * 1.0f;
spinZ += (float)(yMouse - mousePosY) * 1.0f;
mousePosX = xMouse;
mousePosY = yMouse;
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho((GLdouble)-w / 2, (GLdouble)w / 2, (GLdouble)-h / 2, (GLdouble)h / 2, 350.0, -350.0);
//glPointSize(10.0);
//glLineWidth(1.5);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}