Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

barazor

what am i leaving out(texturing)

This topic is 5705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i cant seem to get this to work with my setup...i just keep getting a blank untextured quad. i had it working the other day, unfortunately, i lost the code basically all i am trying to do is texture map a quad with a pre specified color(0x0000ff00 - which should be green in RGBA), which explains the "unsigned int data[height*width]", i just fill it with the 0x0000ff00...basically just doing this for pure entertainment here's the code, it uses GLFW for init, etc, so the glfwXX calls shouldnt be a problem. can anybody show me what i'm leaving out?
    
#include <stdio.h>
#include <stdlib.h>
#include <GL/glfw.h>

void draw_scene (void);
void tex_init (void);

GLuint tex_id;


int
main (void)
{
	int ok;
	int running;

	glfwInit ();

	ok = glfwOpenWindow (320, 200, 8, 8, 8, 8, 24, 0, GLFW_WINDOW);

	if (!ok)
	{
		glfwTerminate ();
		return 0;
	}

	glfwSetWindowTitle ("OpenGL Texture Test");

	glfwEnable (GLFW_STICKY_KEYS);
	glEnable (GL_DEPTH_TEST);
	glEnable (GL_TEXTURE_2D);
	do
	{
		draw_scene ();

		glfwSwapBuffers ();

		running = !glfwGetKey (GLFW_KEY_ESC)
			&& glfwGetWindowParam (GLFW_OPENED);
	}
	while (running);

	glfwTerminate ();
	return 0;
}

void
draw_scene (void)
{
	int width, height;

	glfwGetWindowSize (&width, &height);

	height = height < 1 ? 1 : height;

	glViewport (0, 0, width, height);
	glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluPerspective (65.0, (GLdouble) width / (GLdouble) height, 1.0,
			100.0);

	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
	gluLookAt (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	// do stuff here :)

	glBindTexture (GL_TEXTURE_2D, tex_id);

	glBegin (GL_QUADS);

	glTexCoord2f (0.0f, 1.0f);	// top left

	glVertex3f (-1, 1, 0);

	glTexCoord2f (0.0f, 0.0f);	// bottom left

	glVertex3f (-1, -1, 0);

	glTexCoord2f (1.0f, 0.0f);	// bottom right

	glVertex3f (1, -1, 0);

	glTexCoord2f (1.0f, 1.0f);	// top right

	glVertex3f (1, 1, 0);

	glEnd ();
}

void
tex_init (void)
{
	const int tex_dim = 64;
	const int tex_size = (tex_dim * tex_dim);
	unsigned int data[64 * 64];
	int i;


	for (i = 0; i < tex_size; ++i)
		data[i] = 0x00ff0000;

	glGenTextures (1, &tex_id);

	glBindTexture (GL_TEXTURE_2D, tex_id);

	gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGBA8, tex_dim, tex_dim, GL_RGBA,
			   GL_UNSIGNED_INT, data);

	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
			 GL_LINEAR);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
			 GL_LINEAR);
}
    
[edited by - barazor on December 3, 2002 12:55:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Call tex_init().

Share this post


Link to post
Share on other sites
ok. i am going to seriously smack myself for that one

sometimes it pays to have people look at your code...thanks :D

Share this post


Link to post
Share on other sites

  • 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!